【发布时间】:2023-01-07 22:15:38
【问题描述】:
在代码的近端,我希望它根据分数显示某人的表现。如果你得到 5 分,它应该显示“Perfect”,如果你得到 4 分,它应该显示“Great”,如果你得到 3 分,它应该显示“Good”,如果是 2 分,它应该显示“Nice Try”,如果是 1 分,“Try better next time”,如果是 0 分,则显示“You Failed” . 此外,每次您得到正确答案时,都会将其添加到“正确数字的数量”中,如果错误则添加到“错误答案的数量”中。
因此,我尝试了所有方法以使其适用于我目前所知道的有关编码的知识,但仍然无法使用。我尝试更改关系运算符并添加逻辑运算符,但仍然无法正常工作。如果得分为 5,则不会显示任何内容,如果得分为 4,则显示“Perfect”。如果它得到 3 分,它将显示“Great”。如果它得到 2,它将显示“Good”。如果它得到 1,它会显示“Nice Try”。最后,当 0 时,它显示“下次尝试更好”。
#include<stdio.h>
int main(void) {
char choice;
int correctAnswer = 0, wrongAnswer = 0;
printf("1. 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 (choice == 'B')
correctAnswer++;
else
wrongAnswer++;
printf("\n2. In for Loop, the initialization statement is executed___.\n");
printf("A. twice \tC. once\nB. thrice \tD. infinitely");
printf("\nAnswer: ");
scanf(" %c", &choice);
switch (choice)
{
case 'A':
printf("Wrong Answer.\n");
break;
case 'B':
printf("Wrong Answer.\n");
break;
case 'C':
printf("Correct Answer.\n");
break;
case 'D':
printf("Wrong Answer.\n");
break;
default:
printf("Invalid Answer\n");
}
if (choice == 'C')
correctAnswer++;
else
wrongAnswer++;
printf("\n3. What is the meaning of 'percentile' as an operator?\n");
printf("A. Divide \t\tC. remainder after division\nB. module divison \tD. Both B and C");
printf("\nAnswer: ");
scanf(" %c", &choice);
switch (choice)
{
case 'A':
printf("Wrong Answer.\n");
break;
case 'B':
printf("Wrong Answer.\n");
break;
case 'C':
printf("Wrong Answer.\n");
break;
case 'D':
printf("Correct Answer.\n");
break;
default:
printf("Invalid Answer\n");
}
if (choice == 'D')
correctAnswer++;
else
wrongAnswer++;
printf("\n4. char is the most basic type in C.It stores a single character and requires a single byte of memory in almost all compilers.\n");
printf("A. True\nB. False");
printf("\nAnswer: ");
scanf(" %c", &choice);
switch (choice)
{
case 'A':
printf("Correct Answer.\n");
break;
case 'B':
printf("Wrong Answer.\n");
break;
default:
printf("Invalid Answer\n");
}
if (choice == 'A')
correctAnswer++;
else
wrongAnswer++;
printf("\n5. What C statement that is the same with switch?\n");
printf("A. else if\tC. if else if ladder\nB. while loop\tD. none of the above");
printf("\nAnswer: ");
scanf(" %c", &choice);
switch (choice)
{
case 'A':
printf("Wrong Answer.\n");
break;
case 'B':
printf("Wrong Answer.\n");
break;
case 'C':
printf("Correct Answer.\n");
break;
case 'D':
printf("Wrong Answer.\n");
break;
default:
printf("Invalid Answer\n");
}
if (choice == 'C')
correctAnswer++;
else
wrongAnswer++;
printf("\nNumber of Correct Answers: %d\n", correctAnswer++);
printf("Number of Wrong Answers: %d\n", wrongAnswer++);
printf("============================\n\n");
if(correctAnswer == 5)
{
printf("Perfect!\n");
}
else if (correctAnswer == 4)
{
printf("Great!\n");
}
否则如果(correctAnswer == 3)
{
printf("Good!");
}
else if (correctAnswer == 2)
{
printf("Nice Try!\n");
}
else if(correctAnswer == 1)
{
printf("Try better next time!\n");
}
否则如果(correctAnswer == 0)
{
printf("你失败了!");
}
【问题讨论】:
-
删除
printf("\nNumber of Correct Answers: %d\n", correctAnswer++);和printf("Number of Wrong Answers: %d\n", wrongAnswer++);中的++。
标签: c