问题遇到的现象和发生背景
简易计算器器和验证姓名拉一起出问题,运算器单独拉出来可以运行,但是放一起每次第一遍运算的运算符会被吞掉
用代码块功能插入代码,请勿粘贴截图
#include <stdio.h>
#include <string.h>
int main()
{
int count=0;
char x[10];
char name[10]="xiaoming";
while(1)
{
printf("请输入您的姓名:");
scanf("%s",&x);
if (strcmp(x,name)==0){
puts("HELLO");
break;
}
else{
count++;
puts("ERROR");
if (count==3){
printf("错误太多,程序结束!");
return 0;
}
}
}
float m,n;
char op;
while(1)
{
printf("请输入运算符号(+,-,*,/):");
scanf("%c",&op);
printf("请输入第一个数字\n");
scanf("%f",&m);
printf("请输入第二个数字:\n");
scanf("%f",&n);
if(op=='+')
printf("%lf + %lf = %lf\n", m, n, m + n);
else if(op=='-')
printf("%lf - %lf = %lf\n", m, n, m - n);
else if(op=='*')
printf("%lf * %lf = %lf\n", m, n, m* n);
else if(op=='/')
{
if(n==0)
printf("该值不存在!\n");
else
printf("%lf / %lf = %lf\n", m, n, m/n);
}
else{
printf("抱歉,此计算器还没有那么高级!\n");
}
getchar();
}
}