This program asks the user to enter a char and it navigates him to enter two numbers and perform a certain task, the problem is after the switch process the program asks the user to enter another char but it doubles shows twice in the output, it seems that after I tap the key to add a char and make it go into the switch it does the assignment well but after it it ask of me two times in a row to add another character.
void main()
{
char ch;
double sum , num1, num2, maxNumber, minNumber;
printf("Please enter a character: ");
ch = getchar();
while ((ch != 'q') || (ch != 'Q'))
{
switch (ch)
{
case 'a': case'A': // Average number
printf("Please enter two numbers: ");
scanf("%lf%lf", &num1, &num2);
sum = (num1 + num2) / 2;
printf("The average number between %.1lf and %.1lf is %.1lf\n", num1, num2, sum);
if (sum - (int)sum == 0)
printf("The number is an integer\n");
else
printf("The number is not an integer\n");
break;
case'*': // Multiply number
printf("Please enter two numbers: ");
scanf("%lf%lf", &num1, &num2);
sum = num1 * num2;
printf("The multiplied number between %.1lf and %.1lf is %.1lf\n", num1, num2, sum);
break;
case'm':// Show minimum number
printf("Please enter two numbers: ");
scanf("%lf%lf", &num1, &num2);
num1 > num2 ? (minNumber = num2) : (minNumber = num1);
printf("The minimum number is %.1lf\n", minNumber);
break;
case'M':// Show maximum number
printf("Please enter two numbers: ");
scanf("%lf%lf", &num1, &num2);
num1 > num2 ? (maxNumber = num1) : (maxNumber = num2);
printf("The minimum number is %.1lf\n", maxNumber);
break;
case'^':// Perform power between the numbers
printf("Please enter two numbers: ");
scanf("%lf%lf", &num1, &num2);
sum = pow(num1, num2);
printf("The powered number is %.1lf\n", sum);
break;
case'q': case'Q':
printf("The program has ended");
break;
default:
break;
}
printf("Please enter a character: ");
scanf("%c", &ch);
}
}