0

I am trying to make a simple text based menu in C. I am using a infinite while loop and breaking when I get the character to exit the menu. However, after inputing a character that isn't the exit character, it loops through the menu twice before asking for another input. My code is as follows:

while(1){
    printf("Please select an option: \na) Evaluate exponential function\nb) Evaluate sin function\nc) Exit\n");
    scanf("%c",&ch);
    if(ch == 'd')
        {
            break;
        }
}

What could be causing this and how could I fix it? My best guess is that it is grabbing an extra character from the scanf and using that the next time it asks for input.

I appreciate any help with this. Thanks.

Ryan Hosford
  • 519
  • 1
  • 9
  • 25

0 Answers0