gpt4 book ai didi

c - if else 语句在 C 中不起作用

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

#include<stdio.h>

void main()
{
//Declaration
char grade[1];

//Data Input
enter code here
printf("Enter a grade{A,B,C,D,F]: ");
scanf("%c",&grade);

//If Statement

if(grade=='a'=='A')
printf("The score for the grade 'A' is 4.00");
else
if(grade=='b '=='B')
printf("The score for the grade 'B' is 3.00");
else
if(grade=='c'=='C')
printf("The score for the grade 'C' is 2.00");
else
if(grade=='d'=='D')
printf("The score for the grade 'D' is 1.00");

我尝试了很多次,但 if else 语句就是没有弹出我试图让程序识别 A-F 或 a-f 等级的大写和小写。但它似乎不起作用

输入成绩{A,B,C,D,F]:a

进程返回 1 (0x1) 执行时间:2.599 秒按任意键继续。

给我这个

最佳答案

仔细观察:

if(grade=='a'=='A')

相同类型的运算符从左到右,所以这与

if ((grade == 'a') == 'A')

因此,您正在比较 grade'a''A' 的结果。这没有任何意义。

关于c - if else 语句在 C 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39733435/

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