我剛剛開始,我剛剛接觸編程。我正在做一個練習,我必須要求用戶在他或她自己選擇的一段時間內每個月的降雨量。該方案需要顯示年份的總降雨量和每月的平均降雨量。我被困在兩件事上,顯示陣列c中的用戶輸入#
1st是如何得到循環來識別用戶輸入的年數(例如):如果他或她進入2年後,第二年開始一年後。目前它只運行1年。
我的第二個問題是,在一年的結束時,我似乎無法得到用戶輸入的每個月顯示的總數。如何從數組中獲得這些數據。我已將下面的代碼附加到下面。任何幫助我能得到這個是非常讚賞,感謝
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]);
}
}
}
}
嘗試重新發布您的代碼。你沒有正確地做到這一點 –
永遠不要分配一個基本類型名稱與命名空間名稱相同。 –