gpt4 book ai didi

c - 用户输入无效号码时不会出现错误消息

转载 作者:太空狗 更新时间:2023-10-29 15:50:30 25 4
gpt4 key购买 nike

我已经制作了一个可以运行的简单程序,现在我希望当我输入“大于 100 且小于 0”的数字时,它应该显示一条无效数字的消息。

int math,eng,phy;
float f,h;
printf("Enter math marks:");
scanf("%d",&math);
if (math<0 && math>100)
{
printf("You have entered invalid number");
}
printf("Enter eng marks:");
scanf("%d",&eng);
printf("Enter phy marks:");
scanf("%d",&phy);
f=math+eng+phy;
if (f>=90 && h<=100)
{
printf(" You got A grade\n");
}
h=f/300*100;
printf("Your obtained marks=%f\n",f);
printf("Your percentage=%f\n",h);
getch();
}

最佳答案

你应该使用 if(math < 0 || math > 100) ...一个数字不能同时大于 100 和小于 0。

关于c - 用户输入无效号码时不会出现错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25428408/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com