Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/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# 我的while循环不断重复_C# - Fatal编程技术网

C# 我的while循环不断重复

C# 我的while循环不断重复,c#,C#,我试图让我的while循环只在所有主题都被回答之前不断重复,然后它应该停止并显示奖金和最终分数。但我不知道为什么不这么做?请帮忙 namespace Assignment { class Class1 { public static int attempt, sum, AptScore, GenScore, MathScore, EngScore, bonus, TotalScore, FinalScore, choice = 0; public

我试图让我的while循环只在所有主题都被回答之前不断重复,然后它应该停止并显示奖金和最终分数。但我不知道为什么不这么做?请帮忙

namespace Assignment
{
    class Class1
    {
        public static int attempt, sum, AptScore, GenScore, MathScore, EngScore, bonus, TotalScore, FinalScore, choice = 0;
        public static string ans;
        static void Main(string[] args)
        {
            bool stop = false;
            Console.WriteLine("Welcome to this Salisbury University IQ Test game");
            Console.WriteLine();
            Console.WriteLine("How many times have you attempted this test?");
            attempt = Convert.ToInt32(Console.ReadLine());
            while (true)
                if (attempt > 1)
                {
                    Console.WriteLine("You cannot take this test");
                }
                else
                {
                    Console.WriteLine(" \n1. Aptitude \n2. English. \n3. Math \n4. Gk \n5. Exit");
                    choice = Convert.ToInt32(Console.ReadLine());
                    switch (choice)
                    {
                        case 1:
                            Console.WriteLine(" What was the name of the lebanon tyrant who ruled for years unending before he was toppled due to civil war? \nA. Osama Bin laden \nB. Gaddafi \nC. Jonathan ");
                            ans = Console.ReadLine();
                            if (ans == "B" || ans == "b")
                            {
                                AptScore += 10;
                            }
                            break;
                        case 2:
                            Console.WriteLine(" What is the antonym of Pleasure? \nA. Pain \nB. Ecstacy \nC. Wonder");
                            ans = Console.ReadLine();
                            if (ans == "A" || ans == "a")
                            {
                                EngScore += 10;
                            }
                            break;
                        case 3:
                            Console.WriteLine(" What is the sum of 435 and 345? \nA. 799 \nB. 780 \nC. 600 ");
                            ans = Console.ReadLine();
                            if (ans == "B" || ans == "b")
                            {
                                MathScore += 10;
                            }
                            break;
                        case 4:
                            Console.WriteLine(" What year did Nigeria become a republic? \nA. 1960 \nB. 1963 \nC. 1990 ");
                            ans = Console.ReadLine();
                            if (ans == "B" || ans == "b")
                            {
                                GenScore += 10;
                            }
                            break;
                        case 5:
                            Environment.Exit(0);
                            break;
                    }
                    if (stop)
                        break;
                    TotalScore = MathScore + GenScore + EngScore + AptScore;
                    Console.WriteLine("Your total score is : " + TotalScore);
                    if (TotalScore == 10)
                    {
                        Console.WriteLine(" You have no Bonus point ");
                    }
                    else if (TotalScore == 20)
                    {
                        bonus += 2;
                        Console.WriteLine("Your Bonus is {0}", bonus);
                    }
                    else if (TotalScore == 30)
                    {
                        bonus += 5;
                        Console.WriteLine("Your Bonus is {0}", bonus);
                    }
                    else if (TotalScore == 40)
                    {
                        bonus += 10;
                        Console.WriteLine("Your Bonus is {0}", bonus);
                    }
                    else
                    {
                        FinalScore = TotalScore + bonus;
                        Console.WriteLine("Your finalscore is : " + FinalScore);
                    }
                    switch (FinalScore)
                    {
                        case 10:
                            if (FinalScore >= 10)
                            {
                                Console.WriteLine("Your IQ level is below average");
                            }
                            break;
                        case 22:
                            if (FinalScore >= 22)
                            {
                                Console.WriteLine("Your IQ level is average");
                            }
                            break;
                        case 35:
                            if (FinalScore >= 35)
                            {
                                Console.WriteLine("You are intelligent");
                            }
                            break;
                        case 40:
                            if (FinalScore == 40)
                            {
                                Console.WriteLine("You are a genius");
                            }
                            break;
                        default:
                            break;
                    }
                }
        }
    }
}
这永远不会发生。

我明白了:

bool stop = false;
而且:

if (stop)
    break;
但是我从来没有看到一个
stop=true


您打算在何处将stop设置为true?

在何处中断无限循环(
while(true)
)?“我看不出来,”奥德说得很对。while循环没有中断。@JayPatel@Oded:if(stop)break有一个
语句。不幸的是,
stop
从未设置为
true
@abelenky谢谢。我没有注意到。
if (stop)
    break;