954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Number to words continuity

if(num/100>=1)
	{
		x=num/100;
		switch(x)
		{
			case 1: cout<<"one hundred "; break;
			case 2: cout<<"two hundred "; break;
			case 3: cout<<"three hundred "; break;
			case 4: cout<<"four hundred "; break;
			case 5: cout<<"five hundred "; break;
			case 6: cout<<"six hundred "; break;
			case 7: cout<<"seven hundred "; break;
			case 8: cout<<"eight hundred "; break;
			case 9: cout<<"nine hundred "; break;
		}
		num=num%100;
	}

	if(num/10>=1)
	{
		x=num/10;
		switch(x)
		{
			case 2: cout<<"twenty "; break;
			case 3: cout<<"thirty "; break;
			case 4: cout<<"fourty "; break;
			case 5: cout<<"fifty "; break;
			case 6: cout<<"sixty "; break;
			case 7: cout<<"seventy "; break;
			case 8: cout<<"eighty "; break;
			case 9: cout<<"ninety "; break;
		}
	if(num/1>9)
	{
		x=num/1;
		switch(x)
		{
			case 10: cout<<"ten "; break;
			case 11: cout<<"eleven "; break;
			case 12: cout<<"twelve "; break;
			case 13: cout<<"thirteen "; break;
			case 14: cout<<"fourteen "; break;
			case 15: cout<<"fifteen "; break;
			case 16: cout<<"sixteen "; break;
			case 17: cout<<"seventeen "; break;
			case 18: cout<<"eighteen "; break;
			case 19: cout<<"nineteen "; break;
		}
	}
		num=num%10;
	}

	if(num/1>=1)
	{
		x=num/1;
		switch(x)
		{
			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;
		}
	}


Here's my program and here are the outputs:

921 - nine hundred twenty one
912 - nine hundred twelve two
902 - nine hundred two

Now, I can't figure out how I can display 912 as nine hundred twelve and not nine hundred twelve TWO. That's what happens everytime I input numbers with 11 to 19 as the last two digits.

More examples:
911 - nine hundred eleven ONE
319 - three hundred nineteen NINE
717 - seven hundred seventeen SEVEN

Please help. Thank you! :)

pamelaanne05
Newbie Poster
7 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

You need to output the teens OR the ones value -- not both.

If output 00,20-90, output 0-9
but if output 10-19 don't output 0-9

WaltP
Posting Sage w/ dash of thyme
Moderator
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

I think u need to remove the equal from this statement if(num/10>=1)

EngSara
Light Poster
43 posts since May 2008
Reputation Points: 8
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: