Answer:
See explaination
Step-by-step explanation:
//namespace
using System;
using System.Windows.Forms;
//application namespace
namespace TemperatureConversionApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//calculate button click
private void btnCalculate_Click(object sender, EventArgs e)
{
//taking temperature type
string temperatureType = cmbTemperatureType.SelectedItem.ToString();
//taking temperature entered by user
double temperature = double.Parse(txtTemperature.Text);
//taking conversion temperature type
string conversionType = cmbConversionType.SelectedItem.ToString();
//checking temperature type and conversion type
if(temperatureType == "Farenheit" && conversionType == "Celsius")
{
//if Farenheit to Celsius temperature then
double temp = (temperature - 32) * 5 / 9;
//display on the label
lblDetails.Text = temperature.ToString("0.00") + " Farenheit is " + temp.ToString("0.00") + " Celsius";
}
else if (temperatureType == "Farenheit" && conversionType == "Kelvin")
{
//if Farenheit to Kelvin temperature then
double temp = (temperature - 32) * 5 / 9+273.15;
//display on the label
lblDetails.Text = temperature.ToString("0.00") + " Farenheit is " + temp.ToString("0.00") + " Kelvin";
}
else if (temperatureType == "Celsius" && conversionType == "Kelvin")
{
//if Celsius to Kelvin temperature then
double temp = temperature + 273.15;
//display on the label
lblDetails.Text = temperature.ToString("0.00") + " Celsius is " + temp.ToString("0.00") + " Kelvin";
}
else if (temperatureType == "Celsius" && conversionType == "Farenheit")
{
//if Celsius to Farenheit temperature then
double temp = (temperature*9/5) +32;
//display on the label
lblDetails.Text = temperature.ToString("0.00") + " Celsius is " + temp.ToString("0.00") + " Farenheit";
}
else if (temperatureType == "Kelvin" && conversionType == "Farenheit")
{
//if Kelvin to Farenheit temperature then
double temp = (temperature-273.15) * 9 / 5 + 32;
//display on the label
lblDetails.Text = temperature.ToString("0.00") + " Kelvin is " + temp.ToString("0.00") + " Farenheit";
}
else if (temperatureType == "Kelvin" && conversionType == "Celsius")
{
//if Kelvin to Celsius temperature then
double temp = temperature - 273.15;
//display on the label
lblDetails.Text = temperature.ToString("0.00") + " Kelvin is " + temp.ToString("0.00") + " Celsius";
}
else
{
lblDetails.Text = "Select valid temperature conversion unit";
}
}
//Exit button click
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();//close application
}
}
}
check attachment for the windows application