# newbiez! Helppppp

• 12-12-2001
Irene
newbiez! Helppppp
can someone show me how to do this Q ?

read a number and print it out digit by digit as a series of words.Example:the numbers 123 would be printed as"five two three".

thanks a lot,guys..waiting......
• 12-12-2001
cody
Well...

what have you done so far, hm? :)
Ah no...let me guess...nothing?! :rolleyes:

Think about it and begin with some lines, then post your code, I'm sure there'll be some people willing to help...

aloa
cody
• 12-12-2001
venomgts550
I would use an if statement
if(x==1)
cout<<"one";
• 12-12-2001
Unregistered
Since this is homework, I am not going to give you any actual code because then you will not learn. However, I will give you the idea.

Start by having them input an array of characters. Then, use a for loop to go through character by character and display the appropriate word using a switch. Good luck,
• 12-12-2001
Jamazon
Is this what you want??
#include <iostream.h> //text input and output

void main(void)
{
char number[15]; //declare our number
int loop = 0; //what we use to keep track of the number we are up to
cin.getline(number, 20); //get the word into number
cout << "Your Number in Words: \n";
while (number[loop] != '\0') //while not the endd of the loop
{
switch(number[loop++]) //like saying: if (number[loop] == '?')
{
case '1': cout << "One "; break;
case '2': cout << "Two "; break;
case '3': cout << "Three "; break;
case '4': cout << "Four "; break;
case '5': cout << "Five "; break;
case '6': cout << "Six "; break;
case '7': cout << "Seven "; break;
case '8': cout << "Eight "; break;
case '9': cout << "Nine "; break;
case '0': cout << "Zero "; break;
} //end of switch
} //end of loop
cout << "\nPlease Press A Key Then Enter To Exit..."; //sometimes the window will dissapear so put this here.
cin >> loop;
}

That should work. If your using c just change the #induce file and the cin and cout to the c ones.
• 12-12-2001
Leeman_s
well
how exactly does cin.getline work? I know you can put 3 things in the parentheses, the first is the variable to put it in. but then what are the other two things for?
• 12-13-2001
swarm
takes the line with spaces and so forth
• 12-13-2001
Jamazon
cin.getline
the first one is the string (array of characters) to put data into. The second one is how many characters from the line to read (mayby you only want a 5 letter word) and I dont know what the last one does but you don't have to put it there. Hope that helps
• 12-13-2001
venomgts550
the last space is exit condition