using System.Runtime.InteropServices; internal class Program { public static int ValidationNumber() // Method for validating a number and ensuring data has been entered { int UserInput; // defines the UserInput integer do // defines the start of the do while loop { try // tries the code and let's it run { UserInput = int.Parse(Console.ReadLine()); // takes the users input and converts it into an integer using parse 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 Width = 0; // declares width int Length = 0; // declares length int AreaOfGarden = 0; // declares area of garden int AmountOfCarrots = 0; // declares amount of carrots Console.WriteLine("Please enter the width of the garden in CM"); // asks user for width of garden Width = ValidationNumber(); // asks for width and uses function to validate number Console.WriteLine("Please enter the length of the garden in CM"); // asks user for length of garden Length = ValidationNumber(); // asks for length and uses function to validate number AreaOfGarden = Length * Width; // sets areaofgarden to length * width Console.WriteLine("The width of the garden in CM is " + AreaOfGarden + "CM"); // outputs area of garden to user AmountOfCarrots = AreaOfGarden / 64; // works out amount of carrots that can be grown with area of garden Console.WriteLine("The amount of carrots that can be grown in the garden is " + AmountOfCarrots + " !"); // outputs amount of carrots that can be grown Console.ReadKey(); // waits for user to press a key to close the program } }