I wrote this code to turn numbers into words, however when I enter the three-digit number it fails to print out the tens place. I tried changing the order of the declared identifiers and the switch statements but it still skips on printing out the corresponding word for the tens. If I type in 248, for example, the output comes out to be "Two Hundred Eight". Are the identifiers declared correctly? If, not what can I do to fix it?
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
int number;
cout<<"Enter an integer number< 1000:";
cin>>number;
int hundreds=number/100;
int tens=number/10;
int ones=number%10;
switch (hundreds)
{
case (9):
cout<<"Nine Hundred ";
break;
case (8):
cout<<"Eight Hundred ";
break;
case (7):
cout<<"Seven Hundred ";
break;
case (6):
cout<<"Six Hundred ";
break;
case (5):
cout<<"Five Hundred ";
break;
case (4):
cout<<"Four Hundred ";
break;
case (3):
cout<<"Three Hundred ";
break;
case (2):
cout<<"Two Hundred ";
break;
case (1):
cout<<"One Hundred ";
break;
}
switch (tens)
{
case (9):
cout<<"Ninety ";
break;
case (8):
cout<<"Eighty ";
break;
case (7):
cout<<"Seventy ";
break;
case (6):
cout<<"Sixty ";
break;
case (5):
cout<<"Fifty ";
break;
case (4):
cout<<"Fourty ";
break;
case (3):
cout<<"Thirty ";
break;
case (2):
cout<<"Twenty ";
break;
case (1):
{if (ones==1)
cout<<"Eleven";
else if (ones==2)
cout<<"Twelve";
else if (ones==3)
cout<<"Thirteen";
else if (ones==4)
cout<<"Fourteen";
else if (ones==5)
cout<<"Fifteen";
else if (ones==6)
cout<<"Sixteen";
else if (ones==7)
cout<<"Seventeen";
else if (ones==8)
cout<<"Eighteen";
else
cout<<"Nineteen";
break;}
}
switch (ones)
{
case (9):
cout<<"Nine";
break;
case (8):
cout<<"Eight";
break;
case (7):
cout<<"Seven";
break;
case (6):
cout<<"Six";
break;
case (5):
cout<<"Five";
break;
case (4):
cout<<"Four";
break;
case (3):
cout<<"Three";
break;
case (2):
cout<<"Two";
break;
case (1):
cout<<"One";
break;
}