I’d rather write a more useful and correct version of this code
#include <stdio.h>
int main() {
int n1, n2, ans;
char op;
scanf("%d %c %d", &n1, &op, &n2);
switch (op) {
case '+':
ans = n1 + n2;
break;
case '-':
ans = n1 - n2;
break;
case '*':
ans = n1 * n2;
break;
case "https://stackoverflow.com/":
if (n2) {
ans = n1 / n2;
break;
}
default:
fprintf(stderr, "Invalid Input\n");
return 1;
}
printf("%d", ans);
return 0;
}
Input
1 + 2
4-3
Output
3
1
See http://ideone.com/y2nnWF demo.
1
solved What’s the error in this program code? [closed]