internal class Program { //Program to show how variables can store different data types 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 = Int16.Parse(Console.ReadLine()); // takes the users input and converts it into an integer using parse if (UserInput <= 0 || UserInput > 130) // checks if the users age is equal to or below 0 or greater than 130 { Console.WriteLine("Please enter valid data"); // asks the user to enter valid data } else // performs this code if the data entered is valid { break; // breaks out of the do while 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; } public static float ValidationFloat() // Method for validating a whole number or a float and ensuring data has been entered { float UserInput; // defines the UserInput float do // defines the start of the do while loop { try // tries the code and let's it run { UserInput = float.Parse(Console.ReadLine()); // takes the users input and converts it into a float using parse if (UserInput <= 0 || UserInput > 20) // checks if the users number is less than or equal to 0 or greater than 20 { Console.WriteLine("Please enter valid data"); // asks the user to enter valid data } else // performs this code if the data entered is valid { break; // breaks out of the do while 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 (float)UserInput; } public static string ValidationString() // declares a method named ValidationString, used for validating any data and ensuring data has been entered { string Data; // defines the string Data do // beginning of the do while loop { try // performs the code and leads to "catch" if a format exception is given { Data = Console.ReadLine(); // sets the string "Data" to the users input if (Data == "") // checks if the user has entered data for the "Data" string { Console.WriteLine("Please enter data"); // tells the user they need to enter data } else // performed if the user did enter data { break; // breaks out of the do while 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 Data; } private static void Main(string[] args) // The start of the main program { Console.WriteLine("Please enter your surname"); // Asks the user for their surname string UserSurname = ValidationString(); // Sets the string UserSurname to whatever the ValidationString method results in Console.WriteLine("Your surname is " + UserSurname + " !"); // outputs the users surname back to them Console.WriteLine("Please enter your national insurance number"); // Asks the user for their national insurance number string UserNationalInsuranceNumber = ValidationString(); // Sets the string UserNationalInsuranceNumber to whatever the ValidationString method results in Console.WriteLine("Your national insurance number is " + UserNationalInsuranceNumber + " !"); // outputs the users national insurance number back to them Console.WriteLine("Please enter your age"); // Asks the user for their age int UserAge = ValidationNumber(); // Sets the integer UserAge to whatever the ValidationNumber method results in Console.WriteLine("You are " + UserAge + " years old!"); // outputs the users age back to them Console.WriteLine("Please enter a number between 1 and 20 (Including or not including a decimal number)"); // Asks the user for a whole or decimal number between 1 and 20 float UserNumber = ValidationFloat(); // Sets the float UserNumber to whatever the ValidationFloat method results in Console.WriteLine("Your number is " + UserNumber + " !"); //Outputs the users back to them Console.WriteLine("Press enter to exit the program"); // informs the user they must press the enter key to exit the program Console.ReadKey(); // reads a key being pressed resulting in the program closing } }