Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Review_TemperatureConv
  7. {
  8.     class Program
  9.     {
  10.         static void ConvertInchtoCm()
  11.         {
  12.             string inInches;
  13.             double inches = 0;
  14.             double result;
  15.  
  16.             while (inches == 0)
  17.             {
  18.                 Console.WriteLine("Please input measurment to convert to centimentres: ");
  19.                 inInches = Console.ReadLine();
  20.                 inches = errorChecking(inInches);
  21.             }
  22.  
  23.             result = inches * 2.54;
  24.  
  25.             Console.WriteLine("{0} inches is {1} in Centimetres.", inches, result);
  26.  
  27.            
  28.         }
  29.  
  30.         static void ConvertInchtoMm()
  31.         {
  32.             string inInches;
  33.             double inches = 0;
  34.             double result;
  35.  
  36.             while (inches == 0)
  37.             {
  38.                 Console.WriteLine("Please input measurment to convert to milimetres: ");
  39.                 inInches = Console.ReadLine();
  40.                 inches = errorChecking(inInches);
  41.             }
  42.  
  43.             result = inches * 25.4;
  44.  
  45.             Console.WriteLine("{0} inches is {1} in Milimeters.", inches, result);
  46.         }
  47.  
  48.         static void ConvertInchtoFeet()
  49.         {
  50.             string inInches;
  51.             double inches = 0;
  52.             double result;
  53.  
  54.             while (inches == 0)
  55.             {
  56.                 Console.WriteLine("Please input measurment to convert to Feet: ");
  57.                 inInches = Console.ReadLine();
  58.                 inches = errorChecking(inInches);
  59.             }
  60.  
  61.             result = inches * 0.0833333;
  62.  
  63.             Console.WriteLine("{0:F2} inches is {1:F2} in Foot.", inches, result);
  64.         }
  65.  
  66.         static void ConvertInchtoM()
  67.         {
  68.             string inInches;
  69.             double inches = 0;
  70.             double result;
  71.  
  72.             while (inches == 0)
  73.             {
  74.                 Console.WriteLine("Please input measurment to convert to Metres: ");
  75.                 inInches = Console.ReadLine();
  76.                 inches = errorChecking(inInches);
  77.             }
  78.  
  79.             result = inches * 0.0254;
  80.  
  81.             Console.WriteLine("{0} inches is {1} in Metres.", inches, result);
  82.         }
  83.  
  84.         static double errorChecking(string inData)
  85.         {
  86.             double number = 0;
  87.  
  88.             try
  89.             {
  90.                 number = Convert.ToDouble(inData);
  91.             }
  92.             catch (Exception ex)
  93.             {
  94.                 Console.WriteLine(ex.Message);
  95.             }
  96.  
  97.             return number;
  98.         }
  99.  
  100.         static int Menu()
  101.         {
  102.             Console.WriteLine("Please select one of the following options by pressing the corresponding number next to it: ");
  103.             Console.WriteLine("1. Convert from Inch to Cm");
  104.             Console.WriteLine("2. Convert from Inch to Mm");
  105.             Console.WriteLine("3. Convert from Inch to Feet");
  106.             Console.WriteLine("4. Convert from Inch to Metres");
  107.             Console.WriteLine("5. Help");
  108.             Console.WriteLine("6. Exit");
  109.  
  110.             string inData = Console.ReadLine();
  111.             int choice = Convert.ToInt32(errorChecking(inData));
  112.                        
  113.             return choice;
  114.         }
  115.         static void Help()
  116.         {
  117.             Console.WriteLine("To navigate around Menu, you just have to press the number corresponding to the action you want to take." +
  118.             "\nAll the conversions are from Inches to the length available: \n[CM, MM, Feet and Metres]" +
  119.             "\nWhen you are finished just press 6 to exit the program.");
  120.             Console.ReadLine();
  121.         }
  122.         static void Main(string[] args)
  123.         {
  124.             int menuChoice = 0;
  125.  
  126.             while (menuChoice < 7)
  127.             {
  128.                 menuChoice = Menu();
  129.  
  130.                 if (menuChoice == 1)
  131.                 {
  132.                     ConvertInchtoCm();  
  133.                 }
  134.                 else if (menuChoice == 2)
  135.                 {
  136.                     ConvertInchtoMm();
  137.                 }
  138.                 else if (menuChoice == 3)
  139.                 {
  140.                     ConvertInchtoFeet();
  141.                 }
  142.                 else if (menuChoice == 4)
  143.                 {
  144.                     ConvertInchtoM();
  145.                 }
  146.                 else if (menuChoice == 5)
  147.                 {
  148.                     Help();
  149.                 }
  150.                 else if (menuChoice == 6)
  151.                 {
  152.                     Environment.Exit(0);
  153.                 }
  154.                 else
  155.                 {
  156.                     Console.WriteLine("error");
  157.                     menuChoice = 0;
  158.                
  159.                 }
  160.                
  161.             }
  162.         }
  163.     }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement