0

这就是我到目前为止所拥有的。我的问题是,当您输入正确或错误的答案时,没有一个案例响应。我真的不知道从这里去哪里。程序要求您回答两个相乘的随机数。然后它应该给你八个响应之一。

        int result = 0;
        int caseSwitch = 0;

        string question = DoMultiplication(out result);
        Console.WriteLine(question);
        int answer = Convert.ToInt32(Console.ReadLine());

        if (answer == result)
        {
            switch (caseSwitch)
            {
                case 1:
                    Console.WriteLine("Very Good");
                    break;

                case 2:
                    Console.WriteLine("Excellent");
                    break;

                case 3:
                    Console.WriteLine("Nice Work");
                    break;

                case 4:
                    Console.WriteLine("Keep up the good work!");
                    break;

            }

        }
        else
        {
            switch (caseSwitch)
            {


                case 1:
                    Console.WriteLine("No, Please Try Again.");
                    break;

                case 2:
                    Console.WriteLine("Wrong, Try Once More");
                    break;

                case 3:
                    Console.WriteLine("Don't Give Up!");
                    break;

                case 4:
                    Console.WriteLine("No, Keep Trying!");
                    break;
4

3 回答 3

2

caseSwitch 始终为 0,因此您的 switch 将始终失败而无需向控制台写入任何内容。

如果你想要一个随机响应,你可以这样做:

    int result = 0;
    int caseSwitch = new Random().Next(1, 4);

    string question = DoMultiplication(out result);
    Console.WriteLine(question);
    int answer = Convert.ToInt32(Console.ReadLine());

    if (answer == result)
    {
        switch (caseSwitch)
        {
            case 1:
                Console.WriteLine("Very Good");
                break;

            case 2:
                Console.WriteLine("Excellent");
                break;

            case 3:
                Console.WriteLine("Nice Work");
                break;

            case 4:
                Console.WriteLine("Keep up the good work!");
                break;

        }

    }
    else
    {
        switch (caseSwitch)
        {


            case 1:
                Console.WriteLine("No, Please Try Again.");
                break;

            case 2:
                Console.WriteLine("Wrong, Try Once More");
                break;

            case 3:
                Console.WriteLine("Don't Give Up!");
                break;

            case 4:
                Console.WriteLine("No, Keep Trying!");
                break;
于 2013-10-20T16:40:59.993 回答
1

CaseSwitch 始终 = 0。您需要为其分配一个值,并且 - 或为您的开关添加一个默认案例。

于 2013-10-20T16:37:35.437 回答
0

你有你的int caseSwitch = 0;,我没有看到你在代码中将它更改为 1-4 中的任何一个。那么,如果您没有更改 caseSwitch,您希望它做什么...

于 2013-10-20T16:40:48.383 回答