The switch statement truncates due to the fact that a char variable is being associated with the integer variable choice. How can I fix the switch statement so that it recognizes the Q inputted by the user instead of truncating?
Can I scan for a integer or a char and place the value into integer choice?
Code:#define _CRT_SECURE_NO_DEPRECATE #include <stdio.h> //function prototypes void sumIntegers (); void sumDoubles (); void calcFactorial (); int main() { int choice = 0; /*char quit = 0;*/ char Q = 0; printf("\t\tWelcome, please select from the following options.\n\n\n\n"); do { printf("Please choose from the following options:\n\n\t1: Sum of even integers\n\n\t2: Sum of dollar amounts\n\n\t3: Factorial of a number\n\n\tQ: to quit\n\n\t:"); scanf(" %d", &choice); /*scanf(" %c", &choice); */ switch (choice) { case 1 : { sumIntegers (); break; } case 2 : { sumDoubles (); break; } case 3 : { calcFactorial (); break; } case 'Q' : { printf(" Have a nice day.\n\n"); return 0; // break } default : { printf("\n\n\n*** You entered an invalid choice!!! ***\n\n\n"); } } } while(choice != Q || choice > 3 || choice < 1); // make sure to correct quit loop return 0; }