**已关闭。**此问题为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.
1条答案
按热度按时间1qczuiv01#
这个
始终为真。请将其更改为: