Hey all,
I'm working on a lab for programming and have run into a hiccup. Below is a sample of my code (edited for clarity):
#include <stdio.h>
#include <stdlib.h>
char d;
int main (void)
{
printf("*\t\tCharacter Arithmetic\n");
printf("***************************************************\n");
printf("* Please select one of the following options\n");
printf("* Followed by the proper response\n");
printf("***************************************************\n");
printf("* Functions:\n");
printf("* a. isDigit\n");
printf("* b. isLetter\n");
printf("* c. toUpper\n");
printf("* d. toLower\n");
printf("* q. Quit\n");
printf("***************************************************\n");
printf(" CHOOSE A FUNCTION: ");
char f=getchar();
system ("cls");
switch (f)
{
case 'a':
printf("Please enter a digit:");
scanf("%c", &d);
printf("you entered %c", d);
system("PAUSE");
}
}
my problem is that after i choose my function, in this example 'a', my program doesnt wait for me to enter a digit, it skips the scanf command and just jumps straight to the second printf statement in my switch statement.
any guidance would be appreciated
I'm working on a lab for programming and have run into a hiccup. Below is a sample of my code (edited for clarity):
#include <stdio.h>
#include <stdlib.h>
char d;
int main (void)
{
printf("*\t\tCharacter Arithmetic\n");
printf("***************************************************\n");
printf("* Please select one of the following options\n");
printf("* Followed by the proper response\n");
printf("***************************************************\n");
printf("* Functions:\n");
printf("* a. isDigit\n");
printf("* b. isLetter\n");
printf("* c. toUpper\n");
printf("* d. toLower\n");
printf("* q. Quit\n");
printf("***************************************************\n");
printf(" CHOOSE A FUNCTION: ");
char f=getchar();
system ("cls");
switch (f)
{
case 'a':
printf("Please enter a digit:");
scanf("%c", &d);
printf("you entered %c", d);
system("PAUSE");
}
}
my problem is that after i choose my function, in this example 'a', my program doesnt wait for me to enter a digit, it skips the scanf command and just jumps straight to the second printf statement in my switch statement.
any guidance would be appreciated