I wrote a program that solves an equation of two numbers, but in addition to that, I want it to be able to continue to solve longer equations. Ex: ( solves 2 * 4, or 2 * 4 - 5).
I want to put this part of the program's result into a variable and go from there. How do I place the result of the calculation into a variable, and where would it go?
Code:
#include <stdio.h>
#include <string.h>
int main(void) {
int a;
scanf("%d", &a);
char s[2];
scanf("%s", s);
int b;
scanf("%d", &b);
if (strcmp(s, "+") == 0) {
printf("%d", a + b);
return 1;
}
if (strcmp(s, "-") == 0) {
printf("%d", a - b);
return 1;
}
if (strcmp(s, "*") == 0) {
printf("%d", a * b);
return 1;
}
if (strcmp(s, "/") == 0) {
printf("%d", a / b);
return 1;
}
return 0;
}