I´m trying to make a program that tells you if a letter is a vowel o consonant and then ask the user if he/she wants to use the program again.
Using just the switch statement works totally fine. My problem comes when inserting the do-while loop. On the first try, the program works smoothly, but in the second and following loops, after asking the user if he wants to try again by typing 1, the program "jumps" the part where the user writes its input (scanf("%c", &letter)) and executes the rest of the program considering the previously typed 1 as the input and messing up everything.
I´ve tried looking for the answer on similar questions and videos, but I´m quite new and I just can´t grasp it. I have another program with a similar problem. I will really appreciate your help :)
int main()
{
char letter;
int new_try;
do {
printf("Is you letter a vocal or a consonant?\n");
printf ("\nPlease submit a letter:\n");
scanf("%c", &letter);
switch(letter) {
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
printf("This letter is a vowel\n");
break;
default : printf("This letter is a consonant\n");
break;
}
printf("Do you wish to try again?\n [1.Yes 2. No]\n");
scanf("%d", &new_try);
}
while(new_try != 2);
return 0;
}