我在这里做错了什么?

问题描述:

我已经尝试了很多次,但我无法弄清楚有什么问题!请帮我解决这个错误。我在这里做错了什么?

#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

+4

检查的第一行的#include – artm

+2

请复制粘贴的编译器的输出,使用图像的文字是很烦人的,脆(我不能像访问由于一些重定向失败)。 – unwind

+4

'=='运算符不是一个不重要的'any_of_these()'函数。 'if(oper =='+',' - ','*','/','S')'是错误的,你可以**将它重写为'if(oper =='+'|| oper ==' - '|| oper =='*')'但是因为你已经有一个'switch'构造,你可以放弃这个''default'块。请注意,您的错误消息_“错误,请确保您输入...”实际上从未显示过...... –

以下为,规则 - 运算符此

if (oper == '+', '-', '*', '/', 'S') 

是一样的,因为这

if ('-', '*', '/', 'S') 

是一样的,因为这

if ('*', '/', 'S') 

是一样的这

if ('/', 'S') 

是一样的,因为这

if ('S') 

不等于0虽然总是 “真正”。

C11 Standard (draft)

6.5.17逗号运算符

[...]

语义

逗号的左操作数运算符被评估为无效表达式;在它的评估和右操作数的评估之间有一个 序列点。然后评估右边的 操作数;结果有它的类型和价值。

+0

非常感谢! –

首先,谨慎对待你的包容:

#include <`stdio.h> 

应该

#include <stdio.h> 

此外,您不能使用,如果关键字你所做的一切:

if (oper == '+', '-', '*', '/', 'S') 

应该是:

if (oper == '+' || oper =='-' || oper == '*' || oper == '/' || oper == 'S') 
+0

非常感谢! –