code in c skipping over scanf

Solutions on MaxInterview for code in c skipping over scanf by the best coders in the world

showing results for - "code in c skipping over scanf"
Alice
16 Mar 2016
1bool isDigit(char num)
2{
3     if(num>='0' && num<='9')
4     {
5               return true;
6     }    
7}
8
9int main (void)
10{
11char user1 = 0; // declares a character variable for the user inputted function
12char ch; // delcares a character variable for the user inputted character
13
14printf ("*****************************************" // Displays the menu system
15          "\n* Character Arithmetic      *" // the title
16          "\n*****************************************"
17          "\n* Program instructions here *" // short instructions
18          "\n* Program instructions here *" // short instructions
19          "\n*****************************************"
20          "\n* Functions: *" // displays the 5 functions
21          "\n* a. isDigit *"
22          "\n* b. isLetter *"
23          "\n* c. toUpper *"
24          "\n* d. toLower *"
25          "\n* q. Quit *"
26          "\n*****************************************");
27
28  printf (" Choose a function: "); // prompts the user to enter a function    
29  scanf ("%c", &user1); // saves the user input as 'user1'
30  printf ("Enter a character you would like to use the function on: \n"); // asks the user to input a character
31  scanf ("%c", &ch); // saves the user inputted character as 'ch'
32  
33  if ( user1 == 'a' && isDigit(ch) )
34  {
35       printf ("%c is a digit!\n", ch);
36  }
37}