Need Major Help On My Program!!
My program is to calculate the value of an expression involving arithmetic operators. The expression should be evaluated based on operator precedence. The program should prompt the user to input the expression and should indicate the end of the expression by inputting a character E. The expression should have only numeric values and operators to add, subtract, multiply, and divide.
-The program should prompt the user to input only integer values
-the program should be written for integer values in the expression
-Arrays should be used to store the input values of the user
-Output of the program should be an integer value
-Functions can be used if necessary
here is an example that a user might enter
34
*
2
+
9
-
3
E (terminates the program and then should print the answer)
here is what i have written:
#include <stdio.h>
#define MAX 100
int main()
{
int a[MAX];
char b[MAX];
int i = 0;
char c = 'e';
int total = 0;
printf("Welcome to my calculator program. My program\n");
printf("will calculate addition, subtraction, multiplication\n");
printf("and division. So lets start the program\n");
printf("\nEnter an integer then an operator. To end the\n");
printf("program, enter the character E. To use the operators\n");
printf("use + for addition\nuse - for subtraction\nuse * for");
printf("multiplication\nand use / for division\n");
while (c != 'e')
{
scanf("%d", &a[i]);
while(i < MAX) {
scanf("%d", &b[i]);
if(b[i++]=='e') break;
} i++;
}
i = 0;
total = 0;
{
switch(b[i]){
case '*': total *=a[i+1]; break;
case '/': total /=a[i+1]; break;
case '+': total +=a[i+1]; break;
case '-': total =total - a[i+1]; break;
} i++;
}
while (b[i] != 'e');
printf("the total is: %d", total);
return 0;
}