truviet911
10-14-2009, 02:49 AM
Hi guys. i wrote this little program . and been search online for help but no luck. anyways i want it work when a user input some number it give me words for output. example.
input: 123
output: one hundred and three...and so fourth
here is my code.
#include <iostream>
#include <fstream>
using namespace std;
int main() {
int number = 0.0 ;
cout << "enter a number from 1 to 10: ";
cin >>number;
//cout <<"number:"<< endl;
switch (number){
case 1:
cout << "one" << endl;
break;
case 2:
cout << "two" << endl;
break;
case 3:
cout << "three" << endl;
break;
case 4:
cout << "four" << endl;
break;
case 5:
cout << "five" << endl;
break;
case 6:
cout << "six" << endl;
break;
case 7:
cout << "seven" << endl;
break;
case 8:
cout <<"eight" << endl;
break;
case 9:
cout <<"nine" << endl;
break;
case 10:
cout <<"ten" << endl;
break;
default:
cout <<"nothing is enter" << endl;
break;
system("pause");
return 0;
}
}
is there a better way to do it. what happend if a user input something like
40298---the output should be fourty thousand, two hunder and ninety eight
how am i going to do this? i can't just sit there and do the switch statement forever. lolz anyways im really new at c++. hope you guys can help me out
input: 123
output: one hundred and three...and so fourth
here is my code.
#include <iostream>
#include <fstream>
using namespace std;
int main() {
int number = 0.0 ;
cout << "enter a number from 1 to 10: ";
cin >>number;
//cout <<"number:"<< endl;
switch (number){
case 1:
cout << "one" << endl;
break;
case 2:
cout << "two" << endl;
break;
case 3:
cout << "three" << endl;
break;
case 4:
cout << "four" << endl;
break;
case 5:
cout << "five" << endl;
break;
case 6:
cout << "six" << endl;
break;
case 7:
cout << "seven" << endl;
break;
case 8:
cout <<"eight" << endl;
break;
case 9:
cout <<"nine" << endl;
break;
case 10:
cout <<"ten" << endl;
break;
default:
cout <<"nothing is enter" << endl;
break;
system("pause");
return 0;
}
}
is there a better way to do it. what happend if a user input something like
40298---the output should be fourty thousand, two hunder and ninety eight
how am i going to do this? i can't just sit there and do the switch statement forever. lolz anyways im really new at c++. hope you guys can help me out