停止在while循环中写入

停止在while循环中写入

问题描述:

你好

Hello

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class FloatNumbersWhile
    {
        private double sum;

        public void start()
        {
            WriteProgramInfo();
            ReadInPutAndSumNumbers();
            ShowResults();
        }
        private void ReadInPutAndSumNumbers()
        {
            double num = 0.0;
            bool done = false;
            while (!done)
            {
                Console.WriteLine("\nWhat is the number you want nr ");
                num = double.Parse(Console.ReadLine());
                sum += num;
            }

        }




        private void WriteProgramInfo()
        {
            Console.WriteLine("\n\n ++++++ Finnish input type 0 ++++++");

        }
        private void ShowResults()
        {
            Console.WriteLine("-------------------------------------------------------");
            Console.WriteLine("\nThe sum of it is:" + sum);
        }

    }

}



我需要在输入0时停止此操作,以便我可以对输入到行中的值求和,但是当我尝试它时,它仅退出程序并没有求和.



im need to get this to stop when i enter 0 so i can sum upp the values that i put in to the lines but when i tried it only exit the program and dident get to the sum. so can anyone get me a exampel on how to do it or what i need to get in to it?

您尚未完成设置.

只需将其添加到循环中即可:

done = num == 0;
You are not setting done.

Just add this inside your loop:

done = num == 0;