I'm a beginner at C programming and I just finished making a calculator using if-else statements in my code. And now I tried of doing the same using switch-statement, but it is always executing the default. Please look into my code and suggest me what is going wrong. I am currently writing the code in CodeBlock.
int main()
{
printf("\nWhat operation do you want to do:\n\tA)Addition\n\tB)Subtraction\n\tC)Multiplication\n\tD)Division\n");
float num1;
printf("Please enter the first number: ");
scanf("%f", &num1);
float num2;
printf("Please enter the second number: ");
scanf("%f", &num2);
char myChar;
scanf("%c", &myChar);
switch (myChar)
{
case 'A':
printf("The addition of %.2f and %.2f is %.2f", num1, num2, num1 + num2);
break;
case 'B':
printf("The subtraction of %.2f and %.2f is %.2f", num1, num2, num1 - num2);
break;
case 'C':
printf("The multiplication of %.2f and %.2f is %.2f", num1, num2, num1 * num2);
break;
case 'D':
printf("The quotient of %.2f and %.2f is %.2f", num1, num2, num1 / num2);
break;
default :
printf("You enterned incorrect input");
break;
}
return 0;
}
Any help will be appreciated