I'm a Java programmer trying to learn C for a class and man, I can't wrap my head around this. There's no reason why this shouldn't work and yet it doesn't. I'm trying to write a simple calculator app, and no matter how I write it, the first number I input (variable a) ends up being 0, but the 2nd one is fine. With 5 + 6 as input, the output is 6. What am I missing?
#include <stdio.h>
int main()
{
long int a, b, c;
char op;
c = 0;
printf("Enter the expression: ");
scanf("%ld %s %ld", &a, &op, &b);
switch(op){
case('+'): c = a+b; break;
case('-'): c = a-b; break;
case('*'): c = a*b; break;
case('/'): c = a/b; break;
default: break;
}
printf("\n%ld", c);
return 0;
}