【发布时间】:2017-10-17 20:32:06
【问题描述】:
我的应用程序正在接受用户输入(保龄球得分)并将它们平均化。我要解决的问题是允许用户随时停止的要求。我放置了 10 个 int 变量,并假设一个变量不会超过 10。我的问题是,我如何保持运行总计/计数,以便如果用户只输入 2 个分数来平均,我只除以 2?感谢您的帮助。
Console.WriteLine("Please input the score of game 1: ");
g1 = ReadLine();
game1 = int.Parse(g1);
Console.WriteLine("Would you like to add more scores? Press 'n' to continue to averaging, press any other key to continue!");
playagain = ReadLine();
if(playagain =="n")
{
calculating();
}
Console.Clear();
这就是我编写程序的方式。我是否要创建一个变量,并在 while 语句中赋值,以声明是否按下了任何其他按钮(程序继续到游戏 2 的另一个用户输入),将 1 添加到变量?
【问题讨论】:
-
您可以使用
List,然后除以Count。 -
使用集合 (
List<int>) 保留任意数量的输入
标签: c# visual-studio oop object