Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我创建了一个多选c#console程序,并设置了一个奖励阶段,但当它达到时,什么都没有显示_C#_Visual Studio 2012_Console_Console Application - Fatal编程技术网

我创建了一个多选c#console程序,并设置了一个奖励阶段,但当它达到时,什么都没有显示

我创建了一个多选c#console程序,并设置了一个奖励阶段,但当它达到时,什么都没有显示,c#,visual-studio-2012,console,console-application,C#,Visual Studio 2012,Console,Console Application,我创建了一个多选c#控制台程序,并设置了一个奖励阶段,如果你得到满分5分,就会触发该阶段,但当它达到满分时,什么也没有显示。 为什么? 除奖金外的所有其他if的工作有人能告诉我如何解决这个问题吗?。 抱歉,如果我的编码很新(int,string,if) }检查分数==5的奖金时,您的最佳分数只能是4。我想你在第五题后忘了增加分数。您必须检查分数==4或在第五个问题后增加分数。这里是更新的代码 { int score = 0; string ansr1 = "";

我创建了一个多选c#控制台程序,并设置了一个奖励阶段,如果你得到满分5分,就会触发该阶段,但当它达到满分时,什么也没有显示。 为什么? 除奖金外的所有其他if的工作有人能告诉我如何解决这个问题吗?。 抱歉,如果我的编码很新(int,string,if)


}

检查分数==5的奖金时,您的最佳分数只能是4。我想你在第五题后忘了增加分数。您必须检查分数==4或在第五个问题后增加分数。这里是更新的代码

 {
        int score = 0;
        string ansr1 = "";
        string ansr2 = "";
        string ansr3 = "";
        string ansr4 = "";
        string ansr5 = "";
        string bonus1 = "";
        Console.WriteLine("Welcome to my quiz user!(please type your'e answers in lower case letters)\nWhat is your'e name?\n");
        string name = Console.ReadLine();
        Console.Clear();
        Console.WriteLine("Okay "+name+" lets start!\n");
        Console.Beep(500, 500);
        Console.Beep(500, 500);
        Console.Beep(500, 500);
        Console.Beep(660, 2500);
        Console.Clear();
        //no.1
        Console.WriteLine("Question 1\nWhat colour is the sky "+name+"?\na.blue\nb.green\nc.red\n");
        ansr1 = Console.ReadLine();
        Console.Clear();
        if (ansr1 == "a")
        {
            score = score + 1;
            Console.WriteLine("Correct!\n"+name+"'s score:"+score+"\n");
        }
        else
        {
            Console.WriteLine("Wrong!\n"+name+"'s score:"+score+"\n");
        }
        Console.Beep(600, 1500);
        Console.Clear();

        //no.2
        Console.WriteLine("Question 2\nHow many stars are there on the american flag "+name+"?\na.21\nb.72\nc.50\n");
        ansr2 = Console.ReadLine();
        Console.Clear();
        if (ansr2 == "c")
        {
            score = score+1;
            Console.WriteLine("Correct\n"+name+"'s score:"+ score+"\n");
        }
        else
        {
            Console.WriteLine("Wrong\n"+name+"'s score:"+score+"\n");
        }

        Console.Beep(700, 1500);
        Console.Clear();
        //no.3
        Console.WriteLine("Question 3\n"+name+",If you were in third place and you over take someone in second place what place would you be in now?\na.first\nb.second\nc.third\n");
        ansr3 = Console.ReadLine();
        Console.Clear();
        if (ansr3 == "b")
        {
            score = score+1;
            Console.WriteLine("Correct\n"+name+"'s score:" + score+"\n");
        }
        else
        {
            Console.WriteLine("Wrong\n"+name+"'s score:" + score+"\n");
        }

        Console.Beep(800, 1500);
        Console.Clear();
        //no.4
        Console.WriteLine("Question 4\n" + name + ",what is the tallest mountain in the world?\na.Everest\nb.Fuji\nc.Bromo\n");
        ansr4 = Console.ReadLine();
        Console.Clear();
        if (ansr4 == "a")
        {
            score = score + 1;
            Console.WriteLine("Correct\n" + name + "'s score:" + score + "\n");
        }
        else
        {
            Console.WriteLine("Wrong\n" + name + "'s score:" + score + "\n");
        }

        Console.Beep(900, 1500);
        Console.Clear();
        //no.5
        Console.WriteLine("Question 3\n" + name + ",If you were in third place and you over take someone in second place what place would you be in now?\na.first\nb.second\nc.third\n");
        ansr5 = Console.ReadLine();
        Console.Clear();
        if ((ansr5 == "b") && (score == 4))
        {
            //bonus level
            Console.WriteLine("Congratulations" + name + "you have scored a perfect 5!\nWould you like to enter the bonus stage?\nIf you lose this you lose the game\nbut if you pass you will receive 5 points.\nYes, or No?");
            bonus1 = Console.ReadLine();
            if (bonus1 == "yes")
            {

            }
            else
            {
                Console.WriteLine();
            }
        }
        else if (ansr5 == "b")
        {
            score = score + 1;
            Console.WriteLine("Correct\n" + name + "'s score:" + score + "\n");
        }


        else
        {
            Console.WriteLine("Wrong\n" + name + "'s score:" + score + "\n");
        }

        Console.Beep(1000, 1500);
        Console.Clear();

        Console.ReadKey();
    }
}

在第五个问题中,您正在检查
score==5
,但它最多只能是4。因为它是空的,所以它什么也不做:)不,奖金水平的确认没有出现,因为我正在测试奖金确认。这不是我在最近没有提出的实际奖金问题。我很高兴能帮助你。:)
 {
        int score = 0;
        string ansr1 = "";
        string ansr2 = "";
        string ansr3 = "";
        string ansr4 = "";
        string ansr5 = "";
        string bonus1 = "";
        Console.WriteLine("Welcome to my quiz user!(please type your'e answers in lower case letters)\nWhat is your'e name?\n");
        string name = Console.ReadLine();
        Console.Clear();
        Console.WriteLine("Okay "+name+" lets start!\n");
        Console.Beep(500, 500);
        Console.Beep(500, 500);
        Console.Beep(500, 500);
        Console.Beep(660, 2500);
        Console.Clear();
        //no.1
        Console.WriteLine("Question 1\nWhat colour is the sky "+name+"?\na.blue\nb.green\nc.red\n");
        ansr1 = Console.ReadLine();
        Console.Clear();
        if (ansr1 == "a")
        {
            score = score + 1;
            Console.WriteLine("Correct!\n"+name+"'s score:"+score+"\n");
        }
        else
        {
            Console.WriteLine("Wrong!\n"+name+"'s score:"+score+"\n");
        }
        Console.Beep(600, 1500);
        Console.Clear();

        //no.2
        Console.WriteLine("Question 2\nHow many stars are there on the american flag "+name+"?\na.21\nb.72\nc.50\n");
        ansr2 = Console.ReadLine();
        Console.Clear();
        if (ansr2 == "c")
        {
            score = score+1;
            Console.WriteLine("Correct\n"+name+"'s score:"+ score+"\n");
        }
        else
        {
            Console.WriteLine("Wrong\n"+name+"'s score:"+score+"\n");
        }

        Console.Beep(700, 1500);
        Console.Clear();
        //no.3
        Console.WriteLine("Question 3\n"+name+",If you were in third place and you over take someone in second place what place would you be in now?\na.first\nb.second\nc.third\n");
        ansr3 = Console.ReadLine();
        Console.Clear();
        if (ansr3 == "b")
        {
            score = score+1;
            Console.WriteLine("Correct\n"+name+"'s score:" + score+"\n");
        }
        else
        {
            Console.WriteLine("Wrong\n"+name+"'s score:" + score+"\n");
        }

        Console.Beep(800, 1500);
        Console.Clear();
        //no.4
        Console.WriteLine("Question 4\n" + name + ",what is the tallest mountain in the world?\na.Everest\nb.Fuji\nc.Bromo\n");
        ansr4 = Console.ReadLine();
        Console.Clear();
        if (ansr4 == "a")
        {
            score = score + 1;
            Console.WriteLine("Correct\n" + name + "'s score:" + score + "\n");
        }
        else
        {
            Console.WriteLine("Wrong\n" + name + "'s score:" + score + "\n");
        }

        Console.Beep(900, 1500);
        Console.Clear();
        //no.5
        Console.WriteLine("Question 3\n" + name + ",If you were in third place and you over take someone in second place what place would you be in now?\na.first\nb.second\nc.third\n");
        ansr5 = Console.ReadLine();
        Console.Clear();
        if ((ansr5 == "b") && (score == 4))
        {
            //bonus level
            Console.WriteLine("Congratulations" + name + "you have scored a perfect 5!\nWould you like to enter the bonus stage?\nIf you lose this you lose the game\nbut if you pass you will receive 5 points.\nYes, or No?");
            bonus1 = Console.ReadLine();
            if (bonus1 == "yes")
            {

            }
            else
            {
                Console.WriteLine();
            }
        }
        else if (ansr5 == "b")
        {
            score = score + 1;
            Console.WriteLine("Correct\n" + name + "'s score:" + score + "\n");
        }


        else
        {
            Console.WriteLine("Wrong\n" + name + "'s score:" + score + "\n");
        }

        Console.Beep(1000, 1500);
        Console.Clear();

        Console.ReadKey();
    }
}