Click here to Skip to main content
12,511,263 members (38,330 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++
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 4-May-10 6:06am
Updated 4-May-10 6:11am
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Google[^] not working where you are?
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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
}
  Permalink  
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_grv 7-May-10 7:47am
   
OK... it works.
Now let's chage it top work up to 1'000'000
:-)
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

What do you think to learn if someone else does your homework for you?
  Permalink  
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?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

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"
}
}
}
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160929.1 | Last Updated 28 May 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100