#include<stdio.h>
#include<math.h>
double max(double x, char ch, double temp,int b,int t)
{
double y;
scanf_s("%lf", &y);
double z;
if (ch == '+')
{
z = x + y;
return z;
}
else if (ch == '-')
{
z = x - y;
return z;
}
else if (ch == '*')
{
if (t!= 1)
{
z = x * y - (temp * (y - 1));
return z;
}
else
{
z = x * y;
return z;
}
}
else
{
if (t!=1)
{
z = x / y - (temp*(1/y-1));
return z;
}
else
{
z = x / y;
return z;
}
}
}
int main()
{
char ch = 0;
double a;
double sum = 0;
double temp=0;
int c = 1;
int b=0;//判断乘号前是否是连乘
int t=1;//计数器
while (1)
{
scanf_s("%lf", &a);
{
while (ch != '=')
{
ch = getchar();
switch (ch)
{
case '+':
t++;
temp = a;
a = max(a, ch, temp, b, t);
break;
case '-':
t++;
temp = a;
a = max(a, ch, temp, b, t);
break;
case '*':
a = max(a, ch, temp, b, t);
if (t == 1)
{
t++;
}
break;
case'/':
a = max(a, ch, temp, b, t);
if (t == 1)
{
t++;
}
break;
}
}
printf("%lf", a);
}
}
return 0;
}
普通的四则计算器,不过字符崩溃问题还尚未解决