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......
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......
Well...
what have you done so far, hm?
Ah no...let me guess...nothing?!
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
#include "reallife.h"
I would use an if statement
if(x==1)
cout<<"one";
I am a C++ newb
using: Visual C++ 6.0
thanx for any Help
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,
#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
cout << "Please Enter Your Number... \n";
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.
...
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?
takes the line with spaces and so forth
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
...
the last space is exit condition
I am a C++ newb
using: Visual C++ 6.0
thanx for any Help