Skip to content

Instantly share code, notes, and snippets.

@Gofilord
Created September 24, 2014 13:57
Show Gist options
  • Save Gofilord/06dddd52f46721d05a28 to your computer and use it in GitHub Desktop.
Save Gofilord/06dddd52f46721d05a28 to your computer and use it in GitHub Desktop.
int[] amount = new int[12]; // amount of rain at every month
int yearSum = 0, halfSum1 = 0, halfSum2 = 0, overTheAverage = 0;
double yearAvg, halfAvg1, halfAvg2;
for (int i = 0; i < amount.Length; i++)
{
Console.WriteLine("enter the amount of rain for " + (i + 1) + "th month:");
amount[i] = int.Parse(Console.ReadLine());
yearSum += amount[i];
if (i < 6)
halfSum1 += amount[i];
if (i >= 6)
halfSum2 += amount[i];
}
// calculating the averages
yearAvg = (double)(yearSum / 12);
halfAvg1 = (double)(halfSum1 / 6);
halfAvg2 = (double)(halfSum2 / 6);
// finding the amount of months which are over the year average
for (int i = 0; i < amount.Length; i++)
if (amount[i] > yearAvg)
overTheAverage++;
// printing the results
Console.WriteLine("year average: " + yearAvg);
Console.WriteLine("half 1 average: " + halfAvg1);
Console.WriteLine("half 2 average: " + halfAvg2);
Console.WriteLine("amount of months over the average: " + overTheAverage);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment