|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main()
- {
- int num1,num2,count = 0;
- char oper;
- scanf("%d",&num1);
- while (oper!='=')
- {
- oper = getchar();
- scanf("%d",&num2);
- if (oper == '+')
- {
- num1 += num2;
- }
- else if (oper == '-')
- {
- num1 -= num2;
- }
- else if (oper == '*')
- {
- num1 *= num2;
- }
- else if (oper == '/')
- {
- if (num2 == 0)
- {
- count++;
- break;
- }
- num1 /= num2;
- }
- else if (oper == '=')
- {
- break;
- }
-
- else
- {
- count++;
- break;
- }
-
- }
- if (count == 1)
- {
- printf("ERROR");
- }
-
- else
- {
- printf("%d",num1);
- }
-
- system("pause");
- }
复制代码
你这不不是说连续输入俩个等号可以正常运行,而是在等号之后输入任意一个字符才可以运行(当然等号也是一个字符),比如你输入 1+1=a 他还是会显示2的,因为你结束循环的时候,里面又执行了一遍scanf("%d",&num);
|
|