【问题标题】:Need insight with grading in C using switch, and case tags需要使用 switch 和 case 标签深入了解 C 中的评分
【发布时间】:2023-01-30 18:35:38
【问题描述】:
printf("On a scale of (A - F) rate your experience with our Consortium's HR Department\n\n");
char Grading;
    printf("\nEnter a grade: \n\n");
    scanf("%c", &rate);

    switch (Grading) {
    case 'A':
        printf("Perfect!\n\n");
        break;
        case 'B':
        printf("You did good!\n\n");
        break;
    case 'C':
        printf("You did okay\n\n");
        break;
    case 'D':
        printf("At least not bad\n\n");
        break;
    case 'E':
        printf("Bad\n\n");
        break;
    case 'F':
        printf("Awful\n\n");
        break;
    default:
        printf("Please enter only valid grades\n\n");
        
}
return 0;
}

这只是我在代码块中需要帮助的部分。在不同的 visual studio 选项卡上单独执行此操作有效,但与我以前的代码一起;它一直说只输入有效成绩

我尝试在 C 上进行评分。我的代码确实有效,我的意思是确切的评分代码块在不同的选项卡上有效。但是当添加到我以前的代码中时,我正在处理的项目一直说只输入有效成绩。我有点想问是否有一种传统的方法可以将 C 评分块添加到 C 中的项目中

【问题讨论】:

标签: c


【解决方案1】:

在您的 switch 语句中,您正在检查 Grading 的值,但 scanf 将其输出写入 rate

你应该像这样改变你的开关盒:

    switch (rate) {
    [...]
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 2021-02-14
    • 2019-06-09
    相关资源
    最近更新 更多