我是 C# 新手。我一直在研究这个程序并进行研究,但一无所获。目标是让用户输入数字(多少取决于用户)。当他们输入 0 时,它将停止程序并显示输入的最小数字、输入的最大数字以及输入的所有数字的平均值。我没有得到任何错误,我得到了。如果有人可以请指出我正确的方向。
WriteLines 正在返回:
最小数字为 0 最大数字为 0 平均值为:0 计数:5
这是我的代码:
int LOWEST =0;
int HIGHEST=0;
const int STOP = 0;
double average = 0;
int input;
int count = 0;
Console.WriteLine("Enter a number. You can end the program at anytime by entering 0");
input = Convert.ToInt32(Console.ReadLine());
while (input != STOP)
{
for (int i=0; input != STOP; i++)
{
Console.WriteLine("Enter a number. You can end the program at anytime by entering 0");
input = Convert.ToInt32(Console.ReadLine());
count++;
var Out = new int[] { input };
LOWEST = Out.Min();
HIGHEST = Out.Max();
average = Out.Average();
if ((input > LOWEST) || (input < HIGHEST))
{
LOWEST = Out.Min();
}
if (input > HIGHEST)
{
HIGHEST = Out.Max();
}
}
}
Console.WriteLine("Lowest number is {0}", LOWEST);
Console.WriteLine("Highest number is {0}", HIGHEST);
Console.WriteLine("Average is {0}", average);
Console.WriteLine("Count: {0}", count);
Console.ReadLine();