C语言 如何将错误答案算作错误答案?[已结束]

dw1jzc5e  于 2023-01-08  发布在  其他
关注(0)|答案(1)|浏览(120)

**已关闭。**此问题为not reproducible or was caused by typos。当前不接受答案。

这个问题是由打字错误或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
昨天关门了。
Improve this question
在运行中,它显示答案是错还是对,但即使它是错的,它仍然会被添加到正确答案的数量。我该怎么做或添加使它工作?

#include<stdio.h>

int main(void) {
    char choice;
    int correctAnswer = 0, wrongAnswer = 0;

    printf("Who developed C?\n");
    printf("A. Dennis Leary \tC. Dennis Rodman\nB. Dennis Ritchie \tD. Dennis Ruth");
    printf("\nAnswer: ");
    scanf("%c", &choice);

    switch (choice)
    {
    case 'A':
        printf("Wrong Answer.\n");
        break;
    case 'B':
        printf("Correct Answer.\n");
        break;
    case 'C':
        printf("Wrong Answer.\n");
        break;
    case 'D':
        printf("Wrong Answer.\n");
        break;
    default:
        printf("Invalid Answer\n");
        
    }
    if ('B')
        correctAnswer++;
    else
        wrongAnswer++;
    
    printf("Number of Correct Answers: %d\n", correctAnswer++);
    printf("Number of Wrong Answers: %d\n", wrongAnswer++);
}```

I expect the code to add the wrong answers to be added in the Number of Wrong Answers and it seems it recognized all answers as a correct answer.
1qczuiv0

1qczuiv01#

这个

if ('B')

始终为真。请将其更改为:

if (choice == 'B')

相关问题