I am just a newbie in programming.
Code
__________________________________________________
#include <stdio.h>
char result(char);
void main()
{
char opr, a = 'Y';
float num[100], ans, total=0;
do{
int counter=0;
do{
scanf("%f", &num[counter]);
if(counter>0)
{
if (opr == '+')
ans += num[counter];
if(opr == '-')
ans -= num[counter];
if (opr == '*')
ans *= num[counter];
if (opr == '/')
ans /= num[counter];
}
else
{
ans = num[counter];
}
total=ans;
opr=getchar();
opr=getchar();
if (opr == '=')
printf("Total is %.2f", total);
counter++;
}while (opr != '=');
}while (result(a) == 'Y');
}
char result (char x)
{
char answer;
printf("\nDo you wish to continue?\n(Y/N)\n");
scanf("%c", &answer);
scanf("%c", &answer);
return answer;
}
_________________________________________________
How do I compare the operators inserted by the user. We know that the * operator comes before + or - operator. For example,
1+2*3=7
but my simple calculator only performs
1+2*3=9
how do I code it in a way that it follows the rules of operators precedence.
(*This is an assignment)