Write a C# program to design menu driven temperature converter console application.
The program should show following options for temperature conversion to user:
The program should then prompt user to enter the temperature value.
The given value should be converted to the required temperature unit, based on the choice inputted by user.
using System;
namespace Convert_temper
{
class Program
{
public static void Main(string[] args)
{
int menu;
double cels, fahr, temp;
Console.WriteLine("Options:");
Console.WriteLine("(1) Centigrade to Farenheit");
Console.WriteLine("(2) Farenheit to Centigrade");
Console.Write("\nSelect: ");
menu = Convert.ToInt32(Console.ReadLine());
if (menu == 1)
{
Console.Write("Enter temperature in Celsius: ");
temp = Convert.ToDouble(Console.ReadLine());
fahr = temp * 1.8 + 32;
Console.WriteLine("Temperature in Fahrenheit = {0:f2}", fahr);
}
else if (menu == 2)
{
Console.Write("Enter temperature in Fahrenheit: ");
temp = Convert.ToDouble(Console.ReadLine());
cels = (temp - 32) * 5 / 9;
Console.WriteLine("Temperature in Celsius = {0:f2}", cels);
}
else
Console.WriteLine("Invalid selected options");
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
Comments
Leave a comment