I have written a C program that shows user entered option but I think it can be improved further.
I think the two points below can improve the code
I understand that when user enters a value, I need to check if there is a numeric value or not or it is not a lowercase letter.
I'm looking for help to improve the code. I don't understand how to write code for two verification.
C:
#include <stdio.h>
int main(void)
{
char x;
printf (" What's your ANSWER A, B, C, D : ");
scanf("%c", &x);
switch (x)
{
case 'A' :
printf(" Answer A \n");
break;
case 'B' :
printf(" Answer B \n");
break;
case 'C' :
printf(" Answer C \n");
break;
case 'D' :
printf(" Answer D \n");
break;
default :
printf(" Not Valid Answer \n");
}
return 0;
}
- If the user enters a numeric value, it should be indicated that he has entered a numeric value and give a chance to enter a new value.
- If the user enters a small letter it should be indicated that he has entered a small letter and give a chance to enter a new value.
I understand that when user enters a value, I need to check if there is a numeric value or not or it is not a lowercase letter.
I'm looking for help to improve the code. I don't understand how to write code for two verification.