C# 如何修复While循环菜单?

C# 如何修复While循环菜单?,c#,C#,我想让它,所以每次你进入一个菜单,并完成它,它会回到主菜单,你可以选择继续或退出 每次我真正进入菜单时,我都会陷入一个循环,而它不会返回到主菜单,我该如何解决这个问题 static void Main(string[] args) { addFACTS(); Console.WriteLine("Please Pick An Option By Replying Either 1 or 2:\n1. Input Your Medical Conditi

我想让它,所以每次你进入一个菜单,并完成它,它会回到主菜单,你可以选择继续或退出

每次我真正进入菜单时,我都会陷入一个循环,而它不会返回到主菜单,我该如何解决这个问题

  static void Main(string[] args)
    {
        addFACTS();
        Console.WriteLine("Please Pick An Option By Replying Either 1 or 2:\n1. Input Your Medical Conditions & View Them At The End \n2. View Medical Conditions \n 3. Exit");
        bool exit = false;
        while (exit == false)
        {
            bool numberLoop = false;
            while (numberLoop == false)
            {
                string StringInput = Console.ReadLine();
                int input = 0;
                if (int.TryParse(StringInput, out input))
                {
                    numberLoop = true;
                }
                switch (input)
                {
                    case 1:
                        Console.Clear();
                        userInput();
                        Console.Clear();
                        infer();
                        printFACTS();
                        break;
                    case 2:
                        Console.Clear();
                        FACTS["headache"] = true;
                        FACTS["vomiting"] = true;
                        printFACTS();
                        break;
                    case 3:
                        exit = true;
                        Environment.Exit(0);
                        break;
                }
            }
        }          
    }
publicstaticvoidprintfacts()
{
Console.WriteLine(“------------------------------”);
foreach(KeyValuePair事实中的事实)
{
WriteLine(“{0}={1}”,fact.Key,fact.Value);
}
Console.WriteLine(“------------------------------”);
Console.WriteLine(“\n按任意键终止程序…”);
Console.ReadLine();
}
公共静态无效推断()
{
做
{
numberofacts=countFACTS;
事实[“流感”]=事实[“头痛”]&事实[“呕吐”];
事实[“处方抗生素”]=事实[“感染”];
事实[“处方止痛药”]=事实[“头痛”];
事实[“胃肠炎”]=事实[“恶心”]&事实[“疲劳”];
事实[“健康”]=事实[“感染”];
事实[“处方止痛药”]=事实[“处方止痛药”];
}
while(numberofacts!=countFACTS);
}

将console writeline语句放在第一个while循环中

while (!exit)
{
    Console.WriteLine("Please Pick An Option By Replying Either 1 or 2:\n1. Input Your Medical Conditions & View Them At The End \n2. View Medical Conditions \n 3. Exit");
    bool numberLoop = false;
    while (!numberLoop)
    {
       // Rest of your code
    }
}

将console writeline语句放在第一个while循环中

while (!exit)
{
    Console.WriteLine("Please Pick An Option By Replying Either 1 or 2:\n1. Input Your Medical Conditions & View Them At The End \n2. View Medical Conditions \n 3. Exit");
    bool numberLoop = false;
    while (!numberLoop)
    {
       // Rest of your code
    }
}

@Shahidmanzoorb你能给我看一个代码示例吗?我正在绞尽脑汁,你能把
infer
printFACTS
方法的代码贴出来吗。除了在
推断
函数后退出循环之外,一切似乎都正常。它在推断函数中退出do,但不退出numberLoop@ShahidManzoorBhat但是numberLoop从false变为true如果输入是任何整数,则条件是任何数字,而不是3@ShahidManzoorBhat你能给我看一个代码示例吗?我正在绞尽脑汁,你能把
infer
printFACTS
方法的代码贴出来吗。除了在
推断
函数后退出循环之外,一切似乎都正常。它在推断函数中退出do,但不退出numberLoop@ShahidManzoorBhat但是如果输入是任何整数,则numberLoop从false变为true,条件是任何数字,而不是3