My professor just gave this to us today and I plan on working on this right when
ID: 3633852 • Letter: M
Question
My professor just gave this to us today and I plan on working on this right when I get home, but if anybody can help me out beforehand by writing a "skeleton" program for me to work on modify myself, that would be great. Thanks in advance!
Write a program that will prompt the user to enter an integer between 0 and 999, and then print out the English phrase that represents this number. A sample dialog might be:
Enter an integer between 0 and 999: 375
This number in English is three hundred seventy five
The bulk of this program should be a function
void numToEnglish(unsigned int num, char english[]);
The function fills the array english with the string that represents the number num.
Hints. You might find the following arrays of string literals useful:
char* first20[] = {“zero”, “one”, “two”, “three”, “four”, “five”,
“six”, “seven”, “eight”, “nine”, “ten”, “eleven”, “twelve”, “thirteen”, “fourteen”, “fifteen”, “sixteen”, “seventeen”, “eighteen”,
“nineteen”};
char* tens[] = {“twenty”, “thirty”, “forty”, “fifty”, “sixty”,
“seventy”, “eighty”, “ninety”};
Explanation / Answer
please rate - thanks
to get you started
#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("seven");
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.