加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 用户输入无效号码时不显示错误消息

发布时间:2020-12-16 10:10:17 所属栏目:百科 来源:网络整理
导读:我已经制作了一个简单的程序,现在我想要输入“大于100且小于0”的数字,它应该显示无效数字的消息. int math,eng,phy;float f,h;printf("Enter math marks:");scanf("%d",math);if (math0 math100){ printf("You have entered invalid number");}printf("Ente
我已经制作了一个简单的程序,现在我想要输入“大于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 graden");
}
h=f/300*100;
printf("Your obtained marks=%fn",f);
printf("Your  percentage=%fn",h);
getch();
}

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读