Book's Question:
"Write a program that asks the user for a two digit number, then prints the English word for the number. HINT: Break the number into two digits. Use one switch statement to print the word for the first digit (twenty, thirty, etc). Use a second switch statement to print the word for the second digit. Don't forget that the numbers between 11 and 19 require special treatment (and damn those numbers say I!!!!!)"
I've been working on this little program for about 3 hours straight now, so I'm getting ready to throw my computer out the window. The past 2.5 hours of which spent on the 11 - 19 "special treatment" numbers!!!! Arrgggghhh!!!
Well either way, when I run my program, and enter a number (lets say 11) it displays;
The number is 11
& The number is Illegal entry-1
I realize there are two things wrong, but at the moment I'm currently worried about the fact that both printf(blahblah) are being displayed. How do I display only one? Also any information/ideas on how to make something like 9b, b9, bb, or 05 an illegal entry Below is my program:
"Write a program that asks the user for a two digit number, then prints the English word for the number. HINT: Break the number into two digits. Use one switch statement to print the word for the first digit (twenty, thirty, etc). Use a second switch statement to print the word for the second digit. Don't forget that the numbers between 11 and 19 require special treatment (and damn those numbers say I!!!!!)"
I've been working on this little program for about 3 hours straight now, so I'm getting ready to throw my computer out the window. The past 2.5 hours of which spent on the 11 - 19 "special treatment" numbers!!!! Arrgggghhh!!!
Well either way, when I run my program, and enter a number (lets say 11) it displays;
The number is 11
& The number is Illegal entry-1
I realize there are two things wrong, but at the moment I'm currently worried about the fact that both printf(blahblah) are being displayed. How do I display only one? Also any information/ideas on how to make something like 9b, b9, bb, or 05 an illegal entry Below is my program:
Code:
#include <stdio.h>
main(void)
{
int number, first_digit, second_digit;
printf ("Enter a two digit number: ") ;
scanf_s ("%d", &number) ;
first_digit=number/10;
second_digit = number-((first_digit)*10);
printf ("the number is ");
if (number==11)
printf ("eleven\n") ;
else if (number == 12)
printf ("twelve\n") ;
else if (number == 13)
printf ("thirteen\n") ;
else if (number == 14)
printf ("fourteen\n") ;
else if (number == 15)
printf ("fifteen\n") ;
else if (number == 16)
printf ("sixteen\n") ;
else if (number == 17)
printf ("seventeen\n") ;
else if (number == 18)
printf ("eighteen\n") ;
else if (number == 19)
printf ("nineteen\n") ;
printf("The number is: ");
switch (first_digit) {
case 9: printf ("ninety"); break;
case 8: printf ("eighty"); break;
case 7: printf ("seventy"); break;
case 6: printf ("sixty"); break;
case 5: printf ("fifty"); break;
case 4: printf ("forty"); break;
case 3: printf ("thirty"); break;
case 2: printf ("twenty"); break;
default: printf ("Illegal Entry"); break;
}
switch (second_digit) {
case 9: printf ("-nine\n"); break;
case 8: printf ("-eight\n"); break;
case 7: printf ("-seven\n"); break;
case 6: printf ("-six\n"); break;
case 5: printf ("-five\n"); break;
case 4: printf ("-four\n"); break;
case 3: printf ("-three\n"); break;
case 2: printf ("-two\n"); break;
case 1: printf ("-one\n"); break;
case 0: break;
default: printf ("Illegal Entry"); break;
}
return 0 ;
}
Last edited by a moderator: