Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Review_TemperatureConv
- {
- class Program
- {
- static void ConvertInchtoCm()
- {
- string inInches;
- double inches = 0;
- double result;
- while (inches == 0)
- {
- Console.WriteLine("Please input measurment to convert to centimentres: ");
- inInches = Console.ReadLine();
- inches = errorChecking(inInches);
- }
- result = inches * 2.54;
- Console.WriteLine("{0} inches is {1} in Centimetres.", inches, result);
- }
- static void ConvertInchtoMm()
- {
- string inInches;
- double inches = 0;
- double result;
- while (inches == 0)
- {
- Console.WriteLine("Please input measurment to convert to milimetres: ");
- inInches = Console.ReadLine();
- inches = errorChecking(inInches);
- }
- result = inches * 25.4;
- Console.WriteLine("{0} inches is {1} in Milimeters.", inches, result);
- }
- static void ConvertInchtoFeet()
- {
- string inInches;
- double inches = 0;
- double result;
- while (inches == 0)
- {
- Console.WriteLine("Please input measurment to convert to Feet: ");
- inInches = Console.ReadLine();
- inches = errorChecking(inInches);
- }
- result = inches * 0.0833333;
- Console.WriteLine("{0:F2} inches is {1:F2} in Foot.", inches, result);
- }
- static void ConvertInchtoM()
- {
- string inInches;
- double inches = 0;
- double result;
- while (inches == 0)
- {
- Console.WriteLine("Please input measurment to convert to Metres: ");
- inInches = Console.ReadLine();
- inches = errorChecking(inInches);
- }
- result = inches * 0.0254;
- Console.WriteLine("{0} inches is {1} in Metres.", inches, result);
- }
- static double errorChecking(string inData)
- {
- double number = 0;
- try
- {
- number = Convert.ToDouble(inData);
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- return number;
- }
- static int Menu()
- {
- Console.WriteLine("Please select one of the following options by pressing the corresponding number next to it: ");
- Console.WriteLine("1. Convert from Inch to Cm");
- Console.WriteLine("2. Convert from Inch to Mm");
- Console.WriteLine("3. Convert from Inch to Feet");
- Console.WriteLine("4. Convert from Inch to Metres");
- Console.WriteLine("5. Help");
- Console.WriteLine("6. Exit");
- string inData = Console.ReadLine();
- int choice = Convert.ToInt32(errorChecking(inData));
- return choice;
- }
- static void Help()
- {
- Console.WriteLine("To navigate around Menu, you just have to press the number corresponding to the action you want to take." +
- "\nAll the conversions are from Inches to the length available: \n[CM, MM, Feet and Metres]" +
- "\nWhen you are finished just press 6 to exit the program.");
- Console.ReadLine();
- }
- static void Main(string[] args)
- {
- int menuChoice = 0;
- while (menuChoice < 7)
- {
- menuChoice = Menu();
- if (menuChoice == 1)
- {
- ConvertInchtoCm();
- }
- else if (menuChoice == 2)
- {
- ConvertInchtoMm();
- }
- else if (menuChoice == 3)
- {
- ConvertInchtoFeet();
- }
- else if (menuChoice == 4)
- {
- ConvertInchtoM();
- }
- else if (menuChoice == 5)
- {
- Help();
- }
- else if (menuChoice == 6)
- {
- Environment.Exit(0);
- }
- else
- {
- Console.WriteLine("error");
- menuChoice = 0;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement