|
|
检测点11-4
1.在实现相同功能的前提下,上述表达式scanf ("%hhd", & pstud -> brushc) != 1 || ! (pstud -> brushc >= 1 && pstud -> brushc <= 5)还有别的写法吗?
答:软笔书法的等级”不在1到5之间“就是”小于1或者大于5“。即:
scanf ("%hhd", & pstud -> brushc) != 1 || pstud -> brushc < 1 || pstud -> brushc > 5)
2.在为结构成员comput输入浮点数时,未检查数值的有效性。计算机应用科目的考试成绩最低为0分,最高是100分。请修改源文件c1101.c,为它添加代码以检查输入的分数是否在这个范围内。
参考答案:
while (scanf ("%f", & pstud -> comput) != 1 || pstud -> comput < 0 || pstud -> comput > 100) try_again ();
|
|