here's the instructions:
write a c program that prompts the user for two integers and one of the letter codes a, s, m, or d.
a - addition
s - subtraction
m - multiplication
d - division
and here's the code i've written so far:
the problem i'm having is using the switch statement i think.Code:#include <stdio.h> #include <stdlib.h> #include <math.h> main() { int x1, /*first integer value*/ x2; /*second integer value*/ char x; /*a, s, d, or m*/ printf("\aEnter the first integer: "); scanf("%d",&x1); printf("\aEnter the second integer: "); scanf("%d",&x2); printf("\n\a\aYou inputted %d and %d",x1, x2); printf("\n\nEnter one letter code:" "\n a - addition" "\n s - subtraction" "\n d - division" "\n m - multiplication\n\n"); getchar(x); getchar(x); while(scanf("%c",&x)!=EOF) switch(x) { case 'a': case 'A': (float)(x1+x2); break; case 's': case 'S': (float)(x1-x2); break; case 'd': case 'D': (float)(x1/x2); break; case 'm': case 'M': (float)(x1*x2); break; } printf("\n\n%d", x);



LinkBack URL
About LinkBacks




