Trying to write a simple calculater in C. I'm stuck in having the program terminated if letter 'A', 'B', 'C' or 'D' is not entered, otherwise continue. Even though I enter a valid character it never proceeds.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char letter;
float num1,num2;
printf("What operation would you like to perform?\n\tA) Addition\n\tB) Subtraction\n\tC) Multiplication\n\tD) Division\n\n");
scanf("%c", &letter);
if (letter != 'A' || letter != 'B' || letter != 'C' || letter != 'D')
printf("Not a valid operation\n");
return 1;
printf("Please enter first number: ");
scanf("%f", &num1);
printf("Please enter second number: ");
scanf("%f", &num2);
if (letter == 'A' || letter == 'a')
printf("The sum of %f and %f, is %f\n", num1, num2, num1 + num2);
else if (letter == 'B' || letter == 'b')
printf("The difference of %f and %f, is %f\n", num1, num2, num1 - num2);
else if (letter == 'C' || letter == 'c')
printf("The product of %f and %f, is %f\n", num1, num2, num1 * num2);
else if (letter == 'D' || letter == 'd')
printf("The quoation of %f and %f, is %f\n", num1, num2, num1 / num2);
else
printf("The operation was not valid");
return 0;
}
Thank you for your help.
'B'clauses in your if-else ladder."EDIT:"so the original code is still visible.quoation(which should be a 'quotient' in English), in that the code will never be executed because you copied and pasted and forget to edit theBandbintoDandd. We can understand what you intended; compilers won't.