The program will ask the user for a two-digit number and then prints the English
ID: 3620160 • Letter: T
Question
The program will ask the user for a two-digit number and then prints the English translation of that number. This program will only work for positive numbers in the range [10,99]. Three example runs of this program are shown below. User input is underlined.Enter a two-digit number: 39 You entered the number thirty-nine.
Enter a two-digit number: 13 You entered the number thirteen.
Enter a two-digit number: 60 You entered the number sixty.
We are not far in the book only to chapter 5 of where we discuss switch statements.
#include
int main(void)
{ int firstDigit, secDigit;
printf("Enter the first digit of the number:");
scanf("%d",&firstDigit);
printf("Enter the second digit of the number:");
scanf("%d",&secDigit);
get to there then I get lost not even sure if this is the most effircient way to do it???
Explanation / Answer
please rate - thanks #include <stdio.h>#include<conio.h>
int main()
{int n,units,tens;
printf("Enter a two-digit number:(0 to exit): ");
scanf("%d",&n);
while(n!=0)
{
while(n<10||n>99)
{printf("Please enter positive numbers between 10 and 99 ");
printf("Enter a two-digit number:: ");
scanf("%d",&n);
}
printf("You entered the number ");
units=n%10;
tens=n/10;
switch(tens)
{case 1: switch(units)
{case 9:printf("nineteen");
break;
case 8: printf("eighteen");
break;
case 7: printf("seventeen");
break;
case 6: printf("sixteen");
break;
case 5: printf("fifteen");
break;
case 4: printf("fourteen");
break;
case 3: printf("thirteen");
break;
case 2: printf("twelve");
break;
case 1: printf("eleven");
break;
case 0: printf("ten");
break;
}
break;
case 2: printf("twenty ");
break;
case 3: printf("thirty ");
break;
case 4: printf("forty ");
break;
case 5: printf("fifty ");
break;
case 6: printf("sixty ");
break;
case 7: printf("seventy ");
break;
case 8: printf("eighty ");
break;
case 9: printf("ninty ");
break;
}
if(n>20)
{switch(units)
{case 9: printf("nine");
break;
case 8: printf("eight");
break;
case 7: printf("sevent");
break;
case 6: printf("six");
break;
case 5: printf("five");
break;
case 4: printf("four");
break;
case 3: printf("three");
break;
case 2: printf("two");
break;
case 1: printf("one");
break;
}
}
printf(" ");
printf("Enter a two-digit number:(0 to exit): ");
scanf("%d",&n);
}
getch();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.