C语言 如何让它显示?[关闭]

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

这个问题是由打字错误或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
昨天关门了。
此帖子在14小时前编辑并提交审查。
Improve this question
在代码的近端,我希望它根据某人的分数显示他们做得有多好。如果你得了5分,它应该显示"完美",如果你得了4分,它应该显示"很好",如果你得了3分,它应该显示"很好",如果你得了2分,它应该显示"不错的尝试",如果你得了1分,它应该显示"下次更好地尝试",如果你得了0分,它应该显示"你失败了"。另外,每次你得到一个正确的答案,它将被添加到"正确的数字的数量"和"错误的答案的数量",如果错误的。
所以我尝试了所有的方法来使它工作到目前为止我所知道的关于编码的知识,但仍然不起作用。我尝试改变关系运算符和添加逻辑运算符,但仍然不起作用。如果它得到5分,它不会显示任何东西,那么如果它得到4分,它将显示"完美"。如果它得到3分,它将显示"很好"。如果它得到2分,它将显示"好"。如果它得到1分,它将显示"不错的尝试"。最后,当它得到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");

}

否则如果(正确答案== 3)
{

printf("Good!");

}

else if (correctAnswer == 2)

{

    printf("Nice Try!\n");

}

else if(correctAnswer == 1)

{

    printf("Try better next time!\n");

}

否则如果(正确答案== 0)

{

printf("您失败了!");


}
}

wqsoz72f

wqsoz72f1#

这是因为:

printf("\nNumber of Correct Answers: %d\n", correctAnswer++);

printf("Number of Wrong Answers: %d\n", wrongAnswer++);

在代码末尾的这些行中,您只需为每个行添加一个,而不是打印它们,但当您得到5个正确答案时,correctAnswer变量已经是5,因此您也不需要添加1。

printf("\nNumber of Correct Answers: %d\n", correctAnswer);

printf("Number of Wrong Answers: %d\n", wrongAnswer);

相关问题