自学小白求助
#include <stdio.h>int main()
{
float a, b;
char c;
float result;
printf("请输入式子:");
scanf("%f %c %f", &a, &c, &b);
switch (ch)
{
case '-': result = a - b;
case '+': result = a + b;
case '*': result = a * b;
case '/':
if (b = 0)
{
printf("除数不能为0哦!!!");
}
else
{
本帖最后由 jhq999 于 2022-1-23 12:10 编辑
int main()
{
float a, b;
char c;
float result;
printf("请输入式子:");
if(scanf("%f %c %f", &a, &c, &b)<3)return 0;
switch (c)
{
case '-': result = a - b;break;
case '+': result = a + b;break;
case '*': result = a * b;break;
case '/':
if (b == 0)
{
printf("除数不能为0哦!!!");
return 0;
}
else
result = a / b;
break;
}
//if (c=='/'&& b==0)return 0;
printf("%f %c %f = %f", a, c, b,result);
return 0;
}
页:
[1]