gpt4 book ai didi

c - C 的评分点

转载 作者:行者123 更新时间:2023-11-30 20:30:21 25 4
gpt4 key购买 nike

这是我的代码,一切正常,但是当我输入任何字母而不是数字时,它显示 A-。 我只是想知道为什么会发生这种情况。为什么只显示 A-。任何人都可以解释为什么会发生这种情况吗?

#include<stdio.h>
int main(){
int num;
printf("Enter Your number ");
scanf("%d" ,& num);
if(num>79)
{
printf("Congratulation you got A+");
}

else if(num>69)
{
printf("Congratulation you got A ");
}
else if(num>59)
{
printf("Congratulation you got A-");
}
else if(num>49)
{
printf("Congratulation you got B");
}
else if(num>39)
{
printf("Congratulation you got C");
}

else if(num>32)
{
printf("Congratulation you got D");
}
else
{
printf("You are a student like me(Shuvo) \nBetter Luck next time");

}
return 0 ;
}

最佳答案

在使用变量 num 之前将其初始化为。我的意思是替换“int num;”行通过“int num = 0;”。这是我的解决方案

 #include <stdio.h>

int main(){
int num = 0;
printf("Enter Your number ");
scanf("%d", &num);
if (num > 79)
{
printf("Congratulation you got A+");
}

else if (num > 69)
{
printf("Congratulation you got A ");
}
else if (num > 59)
{
printf("Congratulation you got A-");
}
else if (num > 49)
{
printf("Congratulation you got B");
}
else if (num > 39)
{
printf("Congratulation you got C");
}

else if (num > 32)
{
printf("Congratulation you got D");
}
else
{
printf("You are a student like me(Shuvo) \nBetter Luck next time");

}
return 0;
}

关于c - C 的评分点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54496773/

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