如何使程序检查预定义的答案与输入的答案并打印最终结果? [英] How to make program to check predefined answers with the ones that are entered and print the final result ?

查看:95
本文介绍了如何使程序检查预定义的答案与输入的答案并打印最终结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试过使用

I tried using

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

int main()
{
    char a,b;
    int x=1,correct=0,incorrect=0,unattempted=0;
    printf("Enter Answer for Q.%d: ",x);
    scanf("%c",&a);
    x++;

    switch(a)
    {
    case 'A':
        printf("Correct \n");
        correct++;
        break;
    case 'U':
        unattempted++;
        break;
    default:
        printf("Wrong \n");
        incorrect++;
        break;
    }
    printf("Enter Answer for Q.2:");
    scanf("%c",&b);
    x++;
    switch(b)
    {
    case 'A':
        printf("Correct \n");
        correct++;
        break;
    default:
        printf("Wrong \n");
        incorrect++;
        break;
    }
    printf("Correct = %d ; Incorrect = %d ; Unattempted = %d",correct,incorrect,unattempted);
    return 0;
}



但输出为


But get the output as

Enter Answer for Q.1: A
Correct
Enter Answer for Q.2:Wrong
Correct = 1 ; Incorrect = 1 ; Unattempted = 0
Process returned 0 (0x0)   execution time : 2.281 s
Press any key to continue.







有人可以帮我提供代码。




Can somebody please help me with the code.

推荐答案

我们可以...但你不会从中学到很多东西。

相反,请使用调试器。



main 函数的第一行放置断点,并通过调试器运行代码。然后查看您的代码和数据,并找出手动应该发生的事情。然后单步执行每一行检查您预期发生的情况正是如此。如果不是,那就是当你遇到问题时,你可以回溯(或者再次运行并仔细观察)以找出原因。


对不起,但我们不能为你做到这一点 - 时间让你学习一门新的(非常非常有用的)技能:调试!
We could...but you wouldn't learn much from that.
Instead, use the debugger.

Put a breakpoint on the first line in the main function, and run your code through the debugger. Then look at your code and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!


这篇关于如何使程序检查预定义的答案与输入的答案并打印最终结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆