我已经尝试了很多次,但是我不知道出了什么问题!请帮助我解决此错误。
#include <`stdio.h>
int main(void)
{
float accum = 0, number = 0;
char oper;
printf("\nHello. This is a simple 'printing' calculator. Simply enter the number followed");
printf(" by the operator that you wish to use. ");
printf("It is possible to use the standard \noperators ( +, -, *, / ) as well as two extra ");
printf("operators:\n");
printf("1) S, which sets the accumulator; and\n");
printf("2) N, that ends the calculation (N.B. Must place a zero before N). \n");
do
{
printf("\nPlease enter a number and an operator: ");
scanf("%f %c", &number, &oper);
if (number == 0 && oper == 'N')
{
printf("Total = %f", accum);
printf("\nEnd of calculations.");
}
else if (oper == '+', '-', '*', '/', 'S')
{
switch (oper)
{
case 'S':
accum = number;
printf("= %f", accum);
break;
case '+':
accum = accum + number;
printf("= %f", accum);
break;
case '-':
accum = accum - number;
printf("= %f", accum);
break;
case '*':
accum = accum * number;
printf("= %f", accum);
break;
case '/':
if (number != 0)
{
accum = accum / number;
printf("= %f", accum);
}
else
printf("Cannot divide by zero.");
break;
default:
printf("Error. Please ensure you enter a correct number and operator.");
break;
}
}
else
printf("Error. Please ensure you enter a correct number and operator.");
}
while (oper != 'N');
return 0;
}
当我编译此代码时,会出现以下错误,如此处的快照图像所示。
snapshot of error message
最佳答案
遵循,
-operator的规则
if (oper == '+', '-', '*', '/', 'S')
与此相同
if ('-', '*', '/', 'S')
与此相同
if ('*', '/', 'S')
与此相同
if ('/', 'S')
与此相同
if ('S')
这不等于
0
,尽管始终为“true”。从C11 Standard (draft):
关于c - 我在这里做错了什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33519393/