停止在while循环中写入 [英] stop writing in while loop
本文介绍了停止在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;
这篇关于停止在while循环中写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文