Is it possible to compare a number to a letter and make a difference out of it?
What I'm trying to do is:
- Ask the user for a number between
0-10
(choose from a menu) - Check what that number was, if the number isn't between
0-10
it will ask the user for another number
This all works very well until the user inputs a letter (for example 'A').
I'm using scanf()
to store the value that the user inputs in an integer variable. So if the user inputs 'A'
, the value 65 gets stored in the variable.
This is causing me a lot of headache, because I want to make a difference between letters and numbers..
Here's my code for checking the input:
int checkNumber(int input,int low,int high){
int noPass=0,check=input;
if(check<low){
noPass=1;
}
if(check>high){
noPass=1;
}
if(noPass==1){
while(noPass==1){
printf("Input number between %d - %d \n",low,high);
scanf("%d",&check);
if((check>low)&&(check<high)){
noPass=0;
}
}
}
return check;
}
What happens if the user inputs a letter inside the while loop in this function; it starts looping endlessly asking for an input between low and high.
I want to somehow filter out letters, without actually filtering out the letter's values (65 and above)
.
-Is this possible?