static void Main(string[] args) { int option = 0; do { ChooseOption(ref option); switch (option) { case 1: float circleRadius = 0; UserInputValidation.ValidateUserInputRadius(ref circleRadius, "Enter the radius of the circle"); Area(circleRadius); break; case 2: float widthOfTheRectangle = 0; UserInputValidation.ValidateUserInput(ref widthOfTheRectangle, "Enter the width of the rectangle"); float heightOfTheRectangle = 0; UserInputValidation.ValidateUserInput(ref heightOfTheRectangle, "Enter the height of the rectangle"); AreaRectangle(widthOfTheRectangle, heightOfTheRectangle); break; case 3: float cylinderRadius = 0; UserInputValidation.ValidateUserInputRadius(ref cylinderRadius, "Enter the radius of the cylinder"); float cylinderHeight = 0; UserInputValidation.ValidateUserInput(ref cylinderHeight, "Enter the height of the cylinder"); Area(cylinderRadius, cylinderHeight); break; } } while (option != 4); }
///<summary> //Calculating the surface of a circle based on the given radius ///</summary> public static void CalculateSurface() { double circleRadius = 0; UserInputValidation.ValidateUserInput(ref circleRadius, "Enter the radius of the circle"); double surface = Math.PI * Math.Pow(circleRadius, 2); Console.WriteLine("The surface of the circle is, {0:F2}", surface); }
///<summary> ///Function that read in and validates the option of the user ///</summary> public static void ChooseOption(ref int option) { do { Console.WriteLine("1. Calculate the area of a circle"); Console.WriteLine("2. Calculate the area of a rectangle"); Console.WriteLine("3. Calculate the area of a cylinder"); Console.WriteLine("4. Exit"); UserInputValidation.ValidateUserInput(ref option, "Choose an option"); } while (!(option == 1 || option == 2 || option == 3 || option == 4)); }
///<summary> //Convert celsius to fahrenheit and kelvin and vice-versa ///</summary> public static void CalculateTemperature() { float temperatureInCelsiusDegree = 0, temperatureInKelvin = 0, temperatureInFahrenheit = 0; UserInputValidation.ValidateUserInput(ref temperatureInCelsiusDegree, "Enter the temperature in Celsius"); UserInputValidation.ValidateUserInput(ref temperatureInKelvin, "Enter the temperature in Kelvin"); UserInputValidation.ValidateUserInput(ref temperatureInFahrenheit, "Enter the temperature in Fahrenheit"); float temperatureConversionCelsiusToKelvin = (float)temperatureInCelsiusDegree + (float)273.15; double temperatureConversionCelsiusToFahrenheit = temperatureInCelsiusDegree * 9 / 5 + 32; double temperatureConversionKelvinsToCelsius = temperatureInKelvin - 273.15; double temperatureConversionFahrenheitToCelsius = (temperatureInFahrenheit - 32) * 5 / 9; Console.WriteLine("{0} °C in Kelvin is {1}K ", temperatureInCelsiusDegree, temperatureConversionCelsiusToKelvin); Console.WriteLine($"{temperatureInCelsiusDegree} °C celsius in fahrenheit is {temperatureConversionCelsiusToFahrenheit:F2}"); Console.WriteLine("{0} Kelvin in celsius is {1}", temperatureInKelvin, temperatureConversionKelvinsToCelsius); Console.WriteLine($"{temperatureInFahrenheit} °F in celsius is {temperatureConversionFahrenheitToCelsius}"); }
static void Main(string[] args) { int number = 0; UserInputValidation.ValidateUserInput(ref number, "Enter a number"); OddAndEvenNumbers(number); Console.WriteLine(); int grade = 0; UserInputValidation.ValidateUserInput(ref grade, "Enter your grade"); SpecifyGrade(grade); Console.WriteLine(); string userInput = string.Empty; UserInputValidation.ValidateUserInput(ref userInput, "Enter your string "); char symbolToFindInUserInput = ' '; UserInputValidation.ValidateUserInput(ref symbolToFindInUserInput, "Enter the symbol you want to find "); FindOccurencesOfSymbolInString(userInput, symbolToFindInUserInput); string userInput1 = string.Empty; UserInputValidation.ValidateUserInput(ref userInput1, "Enter your string "); if (isStringPalindrome(userInput1)) { Console.WriteLine($"{userInput1} is Palindrom"); } else { Console.WriteLine($"{userInput1} is NOT Palindrom"); } RecursiveIsStringPalindrome(userInput1); }
static void Main(string[] args) { int year = 0; UserInputValidation.ValidateUserInput(ref year, "Enter a year"); bool IsLeapYear = (year % 4 == 0) && (year % 100 != 0 || year % 400 == 0); List <int> DaysInMonths = IsLeapYear ? new List <int> { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } : new List <int> { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int dayNumber = 0; string month = string.Empty; int day = 0; if (IsLeapYear) { while (!(dayNumber >= 1 && dayNumber <= 366)) { UserInputValidation.ValidateUserInput(ref dayNumber, "Enter a number between 1 and 366"); CalculateMonthAndDayFromDayNumber(DaysInMonths, ref month, ref day, ref dayNumber); } } else { while (!(dayNumber >= 1 && dayNumber <= 365)) { UserInputValidation.ValidateUserInput(ref dayNumber, "Enter a number between 1 and 365"); CalculateMonthAndDayFromDayNumber(DaysInMonths, ref month, ref day, ref dayNumber); } } Console.WriteLine($"{month} {day}"); }