# arithmetic problem

This is a discussion on arithmetic problem within the C Programming forums, part of the General Programming Boards category; here's the instructions: write a c program that prompts the user for two integers and one of the letter codes ...

1. ## arithmetic problem

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.
s - subtraction
m - multiplication
d - division

and here's the code i've written so far:

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 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);```
the problem i'm having is using the switch statement i think.

2. How does that even compile?

1. getchar() doesn't accept a char. It returns an int, though, so use an int.
2. Think your check on scanf() isn't really the best. You should be checking, in this case, if the result of scanf() is equal to 1...
3. Your math inside the cases is stupid since you're not saving the result anywhere. Any decent, modern compiler should be able to tell you this.

Try working on these points for now.... I'd consider turning up the warning level on your compiler.

If you're using GCC, or any varient of it like MinGW, you should be able to turn up the warning level to something really decent.