C/C++ :: Converting Letters To Numbers In A Loop

Jan 25, 2014

I have my program working, as far as converting the letters to numbers, but i want be able to enter as many numbers as i want. so i figured i could put into a loop asking a question at the end. question being whether the user wants to enter another number or not. also i'm assuming the user enters exactly 7 letters each time. this is my code so far.

const int arSize = 9;
char letters[arSize];
int numbers[arSize];
int count = 0;
cout << "Enter a telephone number expressed in letters.
(e.g. CALL loan ( it is not case sensetive))
";
for (int i = 0; i < 7; i++,count++)

[Code] .....

View 14 Replies


ADVERTISEMENT

C :: Converting Letters To Hexadecimal

Jun 3, 2014

i m trying to write a code that would convert a each letter from a text to their decimal images . while i was able to write the part of entering the text , i cant do the converting part , i searched all day on the internet and found nothing.

View 3 Replies View Related

C :: Converting A String Array Into Uppercase Letters From File

Apr 19, 2013

I am new to coding Here is the problem. Have a program prompt the user for a filename to open. Change every alphabetic character in the file to a capital letter. Numbers and special characters should not be changed. Print the output to the screen.

Here is my code so far but i am only returning the last line of text capitalized from the file. I am trying to get the program to display all of the three lines of text from the file capitalized. The program displays the file correctly before i try and convert everything toupper();

Code:

Code: #include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
int main()
{
char line[81], filename[21];
int i;
FILE *inFile;

[Code]...

View 6 Replies View Related

C :: Finding Written Numbers In A String And Converting Them To Decimal Numbers

Jun 20, 2013

User enters sentence "The Smiths have two daughters, three sons, two cats and one dog." (The numbers may change depending on what the user chooses to enter. He told us the range would be from zero to nine.) and we have to convert the written numbers within the sentence into actual decimal numbers and print out the new sentence. Ex. The Smiths have 2 daughters, 3 sons...etc.

I have written the following bit of code which reads the string and finds all the "written numbers" but I am not sure how to proceed from there. I am stuck on how to print out the new sentence with the converted numbers as my professor mentioned something about creating the new string using dynamic memory allocation.

Code:
#include <stdio.h>#include <string.h>
int main () {
char A[100];
int length = 0;
int i;

[Code] .....

View 7 Replies View Related

C :: Writing Numbers In Letters?

Jan 26, 2013

Code:
#include<stdio.h>
#include<string.h>
#define a 9
#define b 9
#define c 3
int main() {

[Code] .....

In practice section there was a challenge to print up numbers in letters up to billion including negatives I didn't look at the solution and came up with this but it is getting difficult after this point....

View 9 Replies View Related

C/C++ :: Shifting Characters - How To Make Letters Loop Back To The Start

Feb 9, 2015

I have to make a function that i'll later be able to use for a ceasar cypher. The letters should shift a user inputted number. This is what I have so far:

char shiftChar(char c, int s) {
char ch = c;
int shift = s;
int newC;
newC = int(ch) + shift;
return newC;
}

The problem with this, is that it doesn't loop back to the start of the alphabet once i get past z.

View 2 Replies View Related

C++ :: Password Hacking - Letters To Numbers

Dec 25, 2014

Okay, so I have a science fair project and I decided on doing a series of programs that show the simpleness behind hacking a password. Each program increases in complexity starting with a four digit password, and ending with a 10 digit letter and number combo that is case sensitive. Right now I need to figure out a way to have my program be able to convert chars into ints, so that I can do a counter and then I also need to be able to convert the ints, back into chars.

View 19 Replies View Related

C# :: Random Generated Numbers And Letters

Feb 13, 2015

I am Currently working on a project and i wish to generate a ID that Contains Numbers letters and a dash for example

000000-A00 The First 0's can be any number but the last 2 needs to between 01 and 12 the letter needs be A B or C

View 5 Replies View Related

C++ :: How To Error Check If User Input Is Letters And Not Numbers

Jun 9, 2014

How do I error check if the user is inputting letters and not numbers? For example, if the user inputs "Lab.txt" I need to display an error message. If they input "Lab2part2.txt" then this is correct and what I want.

I've found a lot of information online on how to error check for numbers or a single letter (EX: 1,2,3, etc. or 'A' 'B' 'C') but nothing for actual WORDS or maybe I should refer to it as a string of characters?

Is there any way to do this? Because my program requires I ask the user to input the name of the file. But the way my code is currently set up is even when the user inputs the wrong file name it still opens the file. I want to prevent this from happening so my thought was to error check user input.

/*Program to determine company's weekly payroll*/

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void OpenTheFile() {
ifstream inputFile;
string filename;
char letter;
int number;

[Code] .....

View 1 Replies View Related

C/C++ :: Loading TXT File To Convert Letters To Numbers And Export Again

Feb 5, 2015

I have been playing around with .txt and .dat files lately. I only manage to load the files, but I don't seem to be able to load files using a variable.

Also modifying the data after it is imported is also currently problematic. I know how to go about the process without the need to import anything, but whenever I import the data I am having trouble modifying/ editing the ".txt" or ".dat" data.

Below is my current code:

#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
ifstream file;
ofstream result;
char in_file_name[8], out_file_name[8];

[Code] ....

View 5 Replies View Related

C++ :: What Data Type That Will Read In Letters And Numbers Form Fstream

Sep 11, 2013

What data_type will read in a string of letters mixed with numbers using fstream :);

View 1 Replies View Related

C :: Converting For Loop To Recursive Function

Jun 10, 2013

I am working on a problem that requires a nest for loop to be converted to a recursive function. I am going to provide just the code instead of the entire program.

Code:

for (R1=1; R1 <+3, R1++){ //for loop
printf (something);
}
// the recursive function
void loopR1 (int R1, int max){
if (R1 <= max){
printf (something);

[Code]...

when calling the recursive function in main i am using the following statement...

loop r1(1,3)

View 4 Replies View Related

C++ :: Converting Numbers Into Words

Mar 13, 2014

I am trying to read into a file that has something like

I have 5 apples and 9 bananas.
Sam has 8 apples and 6 bananas.

and I need to replace the numbers with words. For example I need to change the "5" to five and so on. The problem is that im not sure how to access and then replace just the numbers.

#include <iostream>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main() {
ifstream in_stream;

[Code] ....

View 2 Replies View Related

C++ :: Converting Numbers Into Text

Jul 25, 2012

Take a number that is entered by a user and turn that into printed text. Ex. 85 would be eight five. The problem I am having is I'm not quite sure how to go about this. I don't know if I should use an array, string, or something else.

View 12 Replies View Related

C :: Converting Random Numbers Into Chars?

Apr 3, 2013

I am having difficulty completing 7th last line below I marked the line with an arrow.

Code:
int main(void) {
int MaxNum, /*number of random nos to generate */
i, /*index */
value,

[Code].....

View 4 Replies View Related

C :: Converting Number To Two 4bit Numbers

Aug 14, 2013

Example: If i had the number 5 it needs to be represented/stored as two 4-bit binary numbers,

so 0000 0101, = 0 5.
Or 22 = 0010 0010 = 2 2.

The initial numbers/values are being read from a binary file in to an array....

View 7 Replies View Related

C++ :: Converting Binary Numbers Into Decimal

Apr 25, 2014

This is the question: [URL] .....

Now I have the binary numbers printed out in my code, but I don't know how I can covert them into to decimal.

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main() {
int numberOfDigits;
int numberOfRows;
char flag;

[Code] ....

View 1 Replies View Related

C++ :: Converting Characters To Numbers Using Data Files

Feb 20, 2013

I need to convert characters in a input file to numbers in output file and display both the characters and numbers in a console window.Only 7 numbers can be displayed, the rest needs to be dropped.The input file contains the following data, with one number per line:

CALL HOME
GET LOAN
Hi THERE
BYE FOR NOW

For example, once the first number in the input file has been processed, the console window should display the following: CALL HOME 225 5466.

The output file should now also contain the number:
225 5466

Currently my console is displaying the following:

Enter the input file name.
infile.txt

Enter the output file name.

outfile.txt
2554663Invalid Input
4385626Invalid Input
4Invalid Input
84373Invalid Input
293367669Invalid Input
4357637277CALL HOME
GET LOAN
Hi THERE
BYE FOR NOW

#include <iostream> // for screen/keyboard i/o
#include <fstream> // for file
#include <cstdlib> // for exit
using namespace std;
void openFile(ifstream& infile)

[code]....

View 1 Replies View Related

C++ :: Loop Randomly Until Get All Seven Numbers

Nov 13, 2013

Is it possible to loop randomly. For example

for ( int i = 0; i<= 6 ; i++ )

I don't want i to acsend from 0 to 6 but i want it to get all numbers randomly. For example

first time r = 5 second time r = 2 and so on

until it gets all the seven numbers

View 4 Replies View Related

C++ :: Adding Reciprocals Of The Numbers From 1 To 10 - Loop

May 2, 2014

How to do the problem below using loop?

Using loop...

Output the total of the reciprocals of the numbers from 1 to 10:

1/1 + 1/2 + 1/3 + 1/4 ... + 1/10 = 2.928968

View 3 Replies View Related

C++ :: Display Prime Numbers Using Loop

Feb 3, 2013

We were asked to make a program which displays the prime numbers within the range you inputted... like for example i entered 20 as the upper limit and 1 as the lower, then the program must display all prime numbers within 20 and 1..

and so my problem is, i get to display the prime numbers, but 2, 3, 5, and 7 can't because it think it's with the if statement i made within the loop? (Code below)

#include<iostream.h>
#include<conio.h>
void prime (int up, int low);
main() {
clrscr();
int Upper, Lower, i;

[Code] .....

View 6 Replies View Related

C :: Program To Calculate Factorial Of Numbers - For Loop

Feb 5, 2013

I have been working on a program to calculate the factorial of numbers. Part of my code is copied and modified from the FAQ about validating numbers in user input.

I have encountered a problem with the for loop that I am using near the end of my code. No matter what I do, it seems that my loop only does the multiplication of b = a*(a-1) and then prints. For example, inputting 5 will result in a print of 20, but the factorial is 120.

Code:
int main(void) {
char buf[BUFSIZ];
char *p;
long int a;
long int b;
long int i;

printf ("Enter a number to be factorialized: ");

[Code] ....

View 5 Replies View Related

C :: Determine How Many Numbers In A Range Are Divisible By Third - Loop

Mar 1, 2013

I've pretty much finished the entire program, except for the actual calculation part.

"Given a range of values determine how many integers within that range, including the end points, are multiples of a third value entered by the user. The user should be permitted to enter as many of these third values as desired and your output will be the sum of total multiples found."

I've defined functions to take user input for the low range, high range and a do-while loop to take as many third inputs as the user wants (terminated by entering -1, as requested by the question)

To actually calculate if they're divisible, I found out that if A%B = 0, then they are divisible, so I thought I would create a loop where each value in the range between A and B is checked against the third value to see if they output a zero.

What I need to end up with is a program that tells the user how many integers are divisible by the numbers in the range, i.e: "Enter the low range value: 335 Enter the high range value: 475 Enter a value to check within the range: 17 Enter a value to check within the range: -1 There are 8 total values that are divisible by the numbers in the range." Going back to my original question, how would I create a loop or something to "check" how many values are equal to zero, and consequently increment a variable for each instance? (This is how I think it should be done)

Code:

#include <stdio.h>
//GLOBAL DECLARATIONS
int getlowR();
int gethighR(int);

[Code].....

View 4 Replies View Related

C++ :: For Loop - Summing Numbers (Inputs From User)

Aug 2, 2013

Write a program that computes a running sum of inputs from the user, terminating when the user gives an input value of 0

Using a while loop - no problem. Its only when I try to code it with a for loop that the program doesn't terminate with a 0 input. It terminates with a -1 input!!

while loop

#include <iostream>
using namespace std;
int main() {
float input=1;
float sum = 0;

[Code] ....

View 4 Replies View Related

C++ :: Read A File With 2 Numbers In It - Nested For Loop

Mar 17, 2013

I am attempting to read a file with 2 numbers in it. The first indicates the number of rows the second, the number of columns. So for a file (Data.txt) that contains the numbers 5 7, I want to display

0 0 0 0 0 0 0
1 1 1 1 1 1 1
0 0 0 0 0 0 0
1 1 1 1 1 1 1
0 0 0 0 0 0 0

and write that output to a file.I can display the correct number of rows and columns but I can't figure out how to display alternating rows of 0's and 1's.

#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream inFile;//declare file

[code]....

View 5 Replies View Related

C/C++ :: Same Random Numbers Being Created Every Time Loop Goes Around

May 20, 2013

one of my project involves loop inside loops and creating random numbers. Here is what I have so far:#include <iostream>

#include <string>
#include <cstdlib>
#include <ctime>

[Code]....

so the program will create a random value for the inflow. The idea is that the internal for loop will continue to run until the fill_level of the reservoir, which starts at 0, hits the capacity. The process of simulating how many years (each iteration of the internal for loop representing a year) is to be repeated 10 times by the parent for loop of the water_level simulation for loop.

The problem is that the random number that is supposed to created are the same number. THey are different every time I run it, but they are the same every time the loops repeat to make a new simulation.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved