C语言当中switch case default 这几个关键字写的计算器程序总不对为什么...
发布网友
发布时间:2024-10-19 21:41
我来回答
共2个回答
热心网友
时间:2024-11-17 17:29
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a = 0; int b = 0; char c = 0;
printf("please input a:");
scanf("%d", &a);//去掉\n
getchar();
printf("please operator c:");
scanf("%c", &c);//去掉\n
printf("please input b:");
scanf("%d", &b);//去掉\n
switch (c)
{ case '+': printf("a + b = %d\n", a + b); break;
case '-': printf("a - b = %d\n", a - b); break;
case '*': printf("a * b = %d\n", a * b); break;
case'/':
switch (b)
{
case 0: printf("error\n"); break;
default: printf("a / b = %d\n", a / b);
}
break;//漏了一个break
default:
printf("error\n");
}
system("pause");
return 0;
}
热心网友
时间:2024-11-17 17:32
scanf("%d", &a); 这些scanf的语句中,去除里面的\n
~
~
~