More if else
#include <stdio.h>
int main(void)
{
int a, b;
char ch;
printf("Choice:\n");
printf("(A) Add, (S) Subtract, (M) Multiply, or (D) Divide?\n");
ch = getchar();
printf("\n");
printf("Enter a: ");
scanf("%d", &a);
printf("Enter b: ");
scanf("%d", &b);
if(ch=='A') printf("%d", a+b);
else if(ch=='S') printf("%d", a-b);
else if(ch=='M') printf("%d", a*b);
else if(ch=='D' && b!=0) printf("%d", a/b);
return 0;
}
Related examples in the same category