can you help me on how to convert the numbers into words .
here is my example on how to do that program but im not sure if this is a correct program..
#<iostream.h>
#<conio.h>

int ones,tens,hundreds
main()
{
cout<<"ENTER NUMBER";
cin>>number;
cout<<"ENTER ONES";
cin>>ONES;
if(number==1);
cout<<"one";
else if(number==2);
cout<<"two";
else if(number==3);
cout<<"three";
else if(number==4);
cout<<"four";
else if(number==5);
cout<<"five";

ang so on and so forth ,,,

--this program that i make is too long ..how can i make a short program?help me ..

Use arrays for the strings.

Your comment could have been more descriptive and helpful.

Use arrays for the strings.

By building on what WaltP said, I'm afraid even if you use an array for the strings, ur code will still be long, although not as sequential as you posted it. Solutions I can think of may be optimal but still not short.

look at similar threads.
try to think to implement a class

I think that the first thing to do is to get a container for all the unique words that describe numbers (not compounded). If in English, that's not very hard or very many. The unique numbers run from 0 to 19, then 20-30-40..90 and 100-1000-1000000.., everything else is a compounded of these unique words. I would suggest you use a std::map<int, std::string> to store the associations of the numbers with the corresponding word, but only for those unique numbers. As so:

``````#include <map>

int main() {
std::map<int, std::string> num_words;
num_words = "zero";
num_words = "one";
num_words = "two";
...
num_words = "nineteen";
num_words = "twenty";
num_words = "thirty";
...
num_words = "ninety";
num_words = "hundred";
num_words = "thousand";
num_words = "million";
num_words = "billion";
....

};``````

At this point, you can devise grammar rules to compound those number-words to construct any given number (up to some maximum). The first rule could be:

``````cout<<"ENTER NUMBER";
cin>>number;

if( number < 21 )
cout << num_words[number]; //all numbers from 0 to 20 are not compounded.
else if( number < 100 ) {
cout << num_words[ (number / 10) * 10 ]; //extract the ten-multiple.
if( number % 10 != 0 )
cout << "-" << num_words[ number % 10 ]; //extract the last digit (1 to 9).
} else ....
//... so on for more complicated rules.``````

By building on what WaltP said, I'm afraid even if you use an array for the strings, ur code will still be long, although not as sequential as you posted it. Solutions I can think of may be optimal but still not short.

I don't think 70 lines is that long. 38 lines of actual code from `int main()` to `return 0;`