我已經嘗試了很多次,但我無法弄清楚有什麼問題!請幫我解決這個錯誤。我在這裏做錯了什麼?
#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
檢查的第一行的#include <'stdio.h> – artm
請複製粘貼的編譯器的輸出,使用圖像的文字是很煩人的,脆(我不能像訪問由於一些重定向失敗)。 – unwind
'=='運算符不是一個不重要的'any_of_these()'函數。 'if(oper =='+',' - ','*','/','S')'是錯誤的,你可以**將它重寫爲'if(oper =='+'|| oper ==' - '|| oper =='*')'但是因爲你已經有一個'switch'構造,你可以放棄這個''default'塊。請注意,您的錯誤消息_「錯誤,請確保您輸入...」實際上從未顯示過...... –