【发布时间】:2025-11-25 13:40:01
【问题描述】:
当有人输入大写或小写字母时,我如何打印无效,因为据说他们只输入 0 到 10 之间的浮点数。
我尝试过这样的编码
事情大错特错了。
#include<stdio.h>
int main()
{
int trial=0;
float judge1=0,judge2,judge3,judge4,judge5;
char a;
printf("\n%90s","Welcome to the constentant score calculator program :)");
printf("\n\n\n\n\n\rKindly enter the constentant score by 5 respected
judges:");
do
{
printf("\n\nScore by JUDGE 1 (0-10):\t");
scanf("%f",&judge1);
if ((judge1>-1)&& (judge1<11) )
printf("The constentant got %.2f from the judge",judge1);
else
printf("\aPlease input a valid score between 0 and 10:");
} while ((judge1<0) || (judge1>10)||(judge1=a>96) && (judge1=a<123)||
(judge1=a<91) && (judge1=a>64));
}
好的,这是我的第二个代码
#include<stdio.h>
int main()
{
float judge1;
printf("\n%90s","Welcome to the constentant score calculator program :)");
printf("\n\n\n\n\n\rKindly enter the constentant score by 5 respected
judges:");
printf("\n\nScore by JUDGE 1 (0-10):\t");
scanf("%f",&judge1);
if ((judge1>-1) && (judge1<11))
printf("The constentant got %.2f from the judge",judge1);
else
printf("\aPlease input a valid score between 0 and 10:");
}
}
【问题讨论】:
-
char1的值是什么? -
char1 没有价值......我在插入字母@ThiruShetty 时使用它打印无效
-
@P__J__:
judge1==char1>96不总是零,judge1==char1<123也不总是 1。如果judge1是 1,char1是'|',那么judge1==char1>96是 1 和 @ 987654330@ 为 0。 -
@P__J__ 是的,我希望它以这种方式工作,所以如果他们插入字母,它将打印“请输入 0 到 10 之间的有效分数:”);”,但不幸的是它不起作用那样。
-
@ThiruShetty char1 值取决于字母,使用 ASCII 码。