Create a program that prompts the user to enter a number (0-100000 only) then output the number in words.
Enter a number: 10012
it outputs " ten thousand two" instead of ten thousand twelve...
can you please tell me what are my errors ?
im also having a problem with the 11-19 ten thousandths case ...
here's my program...
Code:
#include <iostream>
using namespace std;
void main()
{
int num,ones,tenths,hundredths,thousandths,tenthousandths,hundredthousandths;
cout<<"Enter a Number: ";
cin>>num;
if (num==0)
cout<<"zero";
if (num>=0&&num<=100000)
{
hundredthousandths=num/100000;
switch (hundredthousandths)
{
case 1:
cout<<" one hundred thousand ";
break;
}
tenthousandths=num/10000;
switch (tenthousandths)
{
case 0:
cout<<" ";
break;
case 1:
cout<<"ten";
break;
case 2:
cout<<"twenty";
break;
case 3:
cout<<"thirty";
break;
case 4:
cout<<"forty";
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;
}
thousandths=num/1000;
switch (thousandths)
{
case 0:
cout<<" thousand ";
break;
case 1:
cout<<" one thousand ";
break;
case 2:
cout<<" two thousand ";
break;
case 3:
cout<<" three thousand ";
break;
case 4:
cout<<" four thousand ";
break;
case 5:
cout<<" five thousand ";
break;
case 6:
cout<<" six thousand ";
break;
case 7:
cout<<" seven thousand ";
break;
case 8:
cout<<" eight thousand ";
break;
case 9:
cout<<" nine thousand ";
break;
}
hundredths=num/100;
switch (hundredths)
{
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;
}
tenths=num/10;
switch (tenths)
{
case 2:
cout<<"twenty ";
break;
case 3:
cout<<"thirty ";
break;
case 4:
cout<<"forty ";
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;
}
ones=num;
if(ones>=1&&ones<=19)
{
switch (ones)
{
case 0:
cout<<" ";
break;
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;
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;
default:
cout <<" Error ";
}
}
cout<<endl;
}
}