准备做一个简单的计算器,要求是当输入s时可以设置初始数字,输入+时开始加法计算,输入减号时开始减法计算,输入e时结束运算程序,能够通过while函数多次循环运算。
#include <stdio.h>
int main(void) {
float x;
char y;
float z;
printf("plz type the basic number\n");
scanf("%f", &x);
printf("u can begin your cauculation");
scanf("%c", &y);
while (y == '+' || y == '-' || y = 's' || y == 'e') {
if (y == '+') {
printf("add\n");
scanf("%f", &z);
x = x + z;
printf("answer %f", x);
}
else if(y == '-') {
printf("minus\n");
scanf("%f", &z);
x = x - z;
printf("answer %f", x);
}
else if (y == 's') {
printf("set the basic value\n");
scanf("%f", &z);
x = z;
printf("now the basic value is %f", x);
}
else {
printf("end the program");
return 0;
}
}
if (y != '+' && y != '-' && y != 's' && y != 'e') {
printf("wrong command, try it by using + - s e");
}
return 0;
}
报错内容为 需要左值作为赋值左操作数
可能会是因为函数限制不准我使用char类型的数据作为参数?