![](/img/trans.png)
[英]C# displaying questions from a string array/ comparing user input with answers from second array
[英]Displaying user input from array c#
我才刚刚开始,所以我是编程新手。 我正在做一个练习,我必须询问用户自己选择的几年中每个月的降雨量,该程序需要显示该年的总降雨量和每月的平均降雨量。 我被困在两件事上,
第一个是我如何获得循环以识别用户输入的年数的方法(例如):如果他或她输入了2年,则一年后第二年开始,第二分钟仅运行一年。
我遇到的第二个问题是,到今年年底,我似乎无法获得用户输入的每个月要显示的总数。如何从数组中获取这些。我在下面附加了代码。 非常感谢我能提供的任何帮助,谢谢
namespace RainFall
{
class Program
{
static void Main(string[] args)
{
int Numyears = 0;
//int Month = 12;
double Rainfall = 0.0;
double avrRainfall = 0.0;
string[] Month = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
Console.WriteLine("please enter number of years");
Numyears = int.Parse(Console.ReadLine());
while(Numyears <= 0)
{
Console.WriteLine("Minimum number of years is 1 Please re-enter");
Numyears = int.Parse(Console.ReadLine());
}
for(int i = 0; i < Month.Length; i ++)
{
Console.WriteLine(" Enter inches of rainfall for {0}", Month[i]);
Console.ReadLine();
}
for (int i = 0;i < Month.Length; i++)
{
Console.WriteLine(" {1} Total;", i + 1, Month[i]);
}
}
}
}
因此,鉴于这是一项学习任务,仅给您答案将对任何人都没有好处,但是我想通过提供一些考虑/询问自己的方法来提供帮助:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.