196k views
4 votes
Create a winform application that lets the user enter a temperature. With a ComboBox object offer the user three choices for input type: Farenheit, Celsius, and Kelvin. Offer the same three choices for the output type. Now when the user clicks the Calculate button, convert them temp and show the user the results.

User Ali Malek
by
5.3k points

1 Answer

0 votes

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

Create a winform application that lets the user enter a temperature. With a ComboBox-example-1
User Ujjwal Wadhawan
by
5.5k points