【发布时间】:2017-02-06 14:59:37
【问题描述】:
#include <stdio.h>
int main() {
char operator;
int a,b;
printf("Enter 1st operands: ");
scanf("%d",&a);
printf("Enter 2nd operands: ");
scanf("%d",&b);
//here after taking the input of integers the code skips to default without
//taking the character input
printf("Enter an operator (+, -, *,/): ");
scanf("%c", &operator);
switch(operator)
{
case '+':
printf("%d+ %d = %d",a, b, a + b);
break;
case '-':
printf("%d- %d = %d",a, b, a - b);
break;
default:
printf("Error! operator is not correct");
}
return 0;
}
【问题讨论】:
-
@xing:请在答案部分写下答案,以便同行评审。
-
您能详细说明一下吗?或提供任何描述性链接?我没有正确理解这件事。蒂亚
标签: c switch-statement character calculator