Click here to Skip to main content
15,868,292 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello,

I need a c++ program that take an integer input value from 1 to 999 and display its word. For example if the user enter 358 then output should be "Three hundred and fifty eight".

Thanks in advance.
Posted
Updated 4-May-10 6:11am
v2

Google[^] not working where you are?
 
Share this answer
 
Should look something like this:


int main()
{
cout<<"Enter an integer between 1 and 999\n";
int a;
cin>>a;

if (a==1)
{
cout<<"One\n";
}
else if (a==2)
{
cout<<"Two\n";
}
else if (a==3)
{
cout<<"Three\n";
}
// else if... repeat till 999
}
 
Share this answer
 
Comments
OriginalGriff 4-May-10 15:03pm    
It has the advantages of working, being very tedious to enter, and failing his course! I like it :laugh:
William Winner 4-May-10 15:04pm    
nice...shouldn't take too long to implement!
Emilio Garavaglia 7-May-10 7:47am    
OK... it works.
Now let's chage it top work up to 1'000'000
:-)
What do you think to learn if someone else does your homework for you?
 
Share this answer
 
Comments
CPallini 4-May-10 13:08pm    
'How to obtain a career in Management', I suppose.
:-)
Sauro Viti 4-May-10 13:17pm    
:-) Hey! You are right! There is someone who like to do my homeworks?
C#
int main()
{
cout<<"Enter an integer between 1 and 999\n";
int a;
cin>>a;
int result[3];
int i;
for(i=0;i<3&&a>0;i++)
{
result[i]=a%10;
a=a/10;
}
if(a<0)
i-=1;

for(int j=i; j>=0;j--)
{
switch(result[j])
{
case 0:
cout<<"zero";
break;
case 1:
cout<<"one";
break;
case 2:
cout<<"two";
break;
.... till "9"
}
}
}
 
Share this answer
 
v3
Comments
CPallini 27-May-13 6:18am    
What's the purpose of adding a wrong solution to a three years old question?
satz_770 28-May-13 1:08am    
Updated it , now check, instead of a simple thing you are writing it from 0 to 999, that made me give this solution!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900