Compiler keeps skipping over the scanf statement!! Please Help.
Hello, I am trying to code a basic program which takes 2 inputs from a user based on a menu and then converts the second input to the menu choice chosen. For example, if 'a' is chosen and the number '5' was inputted then there would be a print stating that 5 is a digit.
Here is the code:
Code:
bool isDigit(char num)
{
if(num>='0' && num<='9')
{
return true;
}
}
int main (void)
{
char user1 = 0; // declares a character variable for the user inputted function
char ch; // delcares a character variable for the user inputted character
printf ("*****************************************" // Displays the menu system
"\n* Character Arithmetic *" // the title
"\n*****************************************"
"\n* Program instructions here *" // short instructions
"\n* Program instructions here *" // short instructions
"\n*****************************************"
"\n* Functions: *" // displays the 5 functions
"\n* a. isDigit *"
"\n* b. isLetter *"
"\n* c. toUpper *"
"\n* d. toLower *"
"\n* q. Quit *"
"\n*****************************************");
printf (" Choose a function: "); // prompts the user to enter a function
scanf ("%c", &user1); // saves the user input as 'user1'
printf ("Enter a character you would like to use the function on: \n"); // asks the user to input a character
scanf ("%c", &ch); // saves the user inputted character as 'ch'
if ( user1 == 'a' && isDigit(ch) )
{
printf ("%c is a digit!\n", ch);
}
}
the problenm occurs when the it is supposed to ask me for my second input (ch) but it seems to just ask me for my input but not scan for it and assign it to ch instead it just exists! I can't seem to find anything wrong.