internal class Program { public static int ValidationNumber() // function 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 if (UserInput < 1) // checks if user input is less than 1 { Console.WriteLine("Error, please enter a number greater than or equal to 1."); // outputs minimum user input to user } else { break; // breaks out of loop } } 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 Radius = 0; // defines radius int Height = 0; // defines height double Pi = 3.142; // defines pi double Volume = 0; // defines volume Console.WriteLine("Please enter the first number"); Radius = ValidationNumber(); // performs validationnumber method on Radius Console.WriteLine("Please enter the second number"); Height = ValidationNumber(); // performs validationnumber method on height int RadiusSquared = Radius * Radius; // calculates radius squared by performing radius * radius Volume = Pi * RadiusSquared * Height / 3; // sets volume to pi * radiussquared * height / 3 Volume = Math.Round(Volume,2); // rounds volume to 2 decimal places Console.WriteLine("The volume is " + Volume); // prints volume to user Console.ReadKey(); // waits for input to close program } }