For this program i'm asking the user to enter a digit and it returns the digit you've entered but in another language. I'm using a switch case to utilize this and for user input errors when typing a letter instead of the digits 0-9 it defaults to invalid user input, however, when I enter 10, 11, or 12 which is outside the range it prints out isa which is number 1 which shouldn't be happening. How do I make it so that if the user enters an invalid number outside the 0-9 range it also says invalid input?
Here's the code
#include <stdio.h>
int main(void) {
printf("This program will display the Filipino(Tagalog) word for a digit of your choice.\n");
printf("Enter a digit 0-9: ");
int digit = getchar();
switch(digit) {
case '0' :
printf("wala\n");
break;
case '1' :
printf("isá\n");
break;
case '2' :
printf("dalawá\n");
break;
case '3' :
printf("tatló\n");
break;
case '4' :
printf("ápat\n");
break;
case '5' :
printf("limá\n");
break;
case '6' :
printf("anim\n");
break;
case '7' :
printf("pitó\n");
break;
case '8' :
printf("waló\n");
break;
case '9' :
printf("siyám\n");
break;
default :
printf("Invalid input\n");
}
return 0;
}
Thank you!