internal class Program { public static Double ValidationDouble() // Method for validating a double and ensuring data has been entered { Double UserInput; // defines the UserInput double do // defines the start of the do while loop { try // tries the code and let's it run { UserInput = Double.Parse(Console.ReadLine()); // takes the users input and converts it into a double using parse if (UserInput <= 0) { Console.WriteLine("Please enter a number above 0"); } else { break; } } catch (FormatException) // performs the code in the event that a format exception has occurred, aka data that shouldn't be entered { Console.WriteLine("Error, unsuitable data entered. Please enter valid data"); // informs the user they have entered unsuitable data } } while (true); // will continuously perform the do while loop until a break has been reached return UserInput; } private static void Main(string[] args) { int a = 5; // defines a as 5, used to define the length of the array double[] Rainfall = new double[a]; // creates the array rainfall using doubles with the length set as "a" int DayCounter = 1; // initialises daycounter used for accurately recording and displaying each days rainfall double TotalRainfall = 0; // initialises totalrainfall double AverageRainfall = 0; // initialises averagerainfall for (int Counter = 0; Counter < a; Counter++) // performs the for loop while the counter is less than a { Console.WriteLine("Please enter day " + DayCounter + "'s rainfall"); // asks user for input while displaying daycounter Rainfall[Counter] = ValidationDouble(); // performs validationdouble method on current rainfall day DayCounter++; // adds 1 to daycounter } for (int Counter = 0; Counter < Rainfall.Length; Counter++) // performs for loop while counter is less than rainfall array length { Console.WriteLine(Rainfall[Counter]); // prints the rainfall day it is currently on TotalRainfall = TotalRainfall + Rainfall[Counter]; // adds current rainfall day to totalrainfall } TotalRainfall = Math.Round(TotalRainfall, 2); // rounds total rainfall to 2 decimal places AverageRainfall = TotalRainfall / Rainfall.Length; // divides totalrainfall by length of array to figure out average rainfall AverageRainfall = Math.Round(AverageRainfall, 2); // rounds average railfall to 2 decimal places Console.WriteLine("The total rainfall is " + TotalRainfall + " rounded to 2 decimal places"); // outputs total rainfall Console.WriteLine("The average rainfall is " + AverageRainfall + " rounded to 2 decimal places"); // outputs average rainfall Console.ReadKey(); // waits for input to close program } }