C#do while循环不起作用

时间:2016-07-20 18:15:15

标签: c# do-while

创建一个我想要循环的程序(对于学校来说是基本的),直到他们输入167.继续我到目前为止所得到的但是它不起作用:

public static void Main(string[] args)
    {
        { }
        Console.WriteLine("Welcome to this swedish sauna!");
        Console.Write("Please enter the desired temperature: ");
        double fahrenheit = double.Parse(Console.ReadLine());
        double celsius = FahrToCels(fahrenheit);
        bool stop = false;
        do
            if (celsius > 77)
            {
                Console.WriteLine("The temperature {0}°C is too high, the highest acceptable temperature is 170°F (77°C).", celsius);
                Console.Write("Please re-enter the temperature that you wish to have: ");
                Console.ReadLine();
            }
            else if (celsius < 73)
            {
                Console.WriteLine("The temperature {0}°C is too low, the lowest acceptable temperature is 163°F (73°C).", celsius);
                Console.Write("Please re-enter the temperature that you wish to have: ");
                Console.ReadLine();
            }
        while (celsius == 75);

            { 
            stop = true;

  Console.WriteLine("You have reached the optimal temperature of the sauna. No more adjustments needed.");
            Console.ReadKey();
        }
    }
    public static double FahrToCels(double fahr)
    {

        double temp = (fahr - 32) * 5 / 9;
        return temp;

我无法让循​​环正常工作,我缺少什么?

1 个答案:

答案 0 :(得分:0)

你遇到的问题不是循环,因为你的&#34;而#34; line应该读取&#34; while(摄氏!= 75);&#34;代替&#34;而(摄氏== 75);&#34;。下一个问题是,当控制台正在读取该行时,您没有将该变量分配给摄氏变量,因此最后一个变量会卡住而不会发生变化。