Hi, I am struggling to finish this C# program. The goal of the program is to con
ID: 3684470 • Letter: H
Question
Hi, I am struggling to finish this C# program. The goal of the program is to convert temperature from Celsius to Fahrenheit and back. Here are the requirements for this program in C#:
Create a Windows Forms application for doing temperature conversions between Celsius and Fahrenheit. Specifically, the application is to have a TextBox for entering the temperature, a Label for displaying converted temperature, a Button for initiating the conversion, and RadioButton s for selecting the conversion direction (from Celsius to Fahrenheit or from Fahrenheit to Celsius)
Explanation / Answer
private void button1_Click(object sender, EventArgs e)
{
double fahrenheit = 0;
double celsius = 0;
if (radioButton1.Checked)
{
if (!double.TryParse(textBox1.Text, out fahrenheit))
{
MessageBox.Show("Please enter a numeric value for Fahrenheit");
return;
}
double finalValue = (fahrenheit - 32) * 5 / 9;
textBox2.Text = finalValue.ToString();
}
else if (radioButton2.Checked)
{
if (!double.TryParse(textBox2.Text, out celsius))
{
MessageBox.Show("Please enter a numeric value for Celsius");
return;
}
double finalValue = (celsius * 9) / 5 + 32;
textBox1.Text = finalValue.ToString();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.