/******************************************************/ /* Introduction to Programming */ /* By Dr. ANTF */ /* www.antf.net */ /* Copyright 2015 */ /* */ /* C# 208 - Problem 5: Temperature Convertor (a) */ /******************************************************/ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DOS { class Program { static void Main(string[] args) { float temp; int userMenu; //display the unit menu Console.WriteLine("Please select the unit to start with: "); Console.WriteLine("\t\tPress (1) for C\n\t\tPress (2) for F\n\t\tPress (3) for K"); Console.Write("Your selection: "); userMenu = int.Parse(Console.ReadLine()); //read the temperature Console.Write("\nPlease enter the temperature: "); temp = float.Parse(Console.ReadLine()); //case of C if(userMenu == 1) { Console.WriteLine("\n\n{0} C ---> {1:0.0000} F", temp, (temp * 9f / 5) + 32); Console.WriteLine("{0} C ---> {1:0.0000} K", temp, temp + 273.15); if (temp <= 0) Console.WriteLine("\nVery Cold"); else if (temp <= 10) Console.WriteLine("\nCold"); else if (temp <= 20) Console.WriteLine("\nWarm"); else if (temp <= 30) Console.WriteLine("\nHot"); else Console.WriteLine("\nVery Hot"); } //case of F else if (userMenu == 2) { Console.WriteLine("\n\n{0} F ---> {1:0.0000} C", temp, (temp - 32) * 5 / 9); Console.WriteLine("{0} F ---> {1:0.0000} K", temp, ((temp - 32) * 5 / 9) + 273.15); temp = (temp - 32) * 5 / 9; if (temp <= 0) Console.WriteLine("\nVery Cold"); else if (temp <= 10) Console.WriteLine("\nCold"); else if (temp <= 20) Console.WriteLine("\nWarm"); else if (temp <= 30) Console.WriteLine("\nHot"); else Console.WriteLine("\nVery Hot"); } //case of K else { Console.WriteLine("\n\n{0} K ---> {1:0.0000} C", temp, temp - 273.15); Console.WriteLine("{0} K ---> {1:0.0000} F", temp, ((temp - 273.15) * 9f / 5) + 32); temp = temp - 273.15f; if (temp <= 0) Console.WriteLine("\nVery Cold"); else if (temp <= 10) Console.WriteLine("\nCold"); else if (temp <= 20) Console.WriteLine("\nWarm"); else if (temp <= 30) Console.WriteLine("\nHot"); else Console.WriteLine("\nVery Hot"); } Console.ReadKey(); } } }