Question
C# I am having trouble this program. So far my temperature converter program is converting temps from C to F. However, whenever I try to
C#
I am having trouble this program. So far my temperature converter program is converting temps from C to F. However, whenever I try to convert F to C, it's keep crashing and displaying an error message, which I can not figure it out and do not know how to fix it. Attached are two screenshots are of message. Do you know what is causing the issue? I would much appreciate your assistance.
namespace Temp Conv { public partial class Form1 : Form { double celsius; double fahrenheit;
public Form1() { InitializeComponent(); } public void ToCelsius(double fah) {
celsius = (fah - 32) * (9 / 5); celsiusTextBox.Text = celsius.ToString(); }
public void ToFahrenheit(double cel) {
fahrenheit = (cel * (9 / 5)) + 32; fahrenheitTextBox.Text = fahrenheit.ToString(); }
private void convertButton_Click(object sender, EventArgs e) { if (celsiusTextBox.Focus()) { celsius = Convert.ToDouble(celsiusTextBox.Text); ToFahrenheit(celsius); }
if (fahrenheitTextBox.Focus()) { fahrenheit = Convert.ToDouble(fahrenheitTextBox.Text); ToCelsius(fahrenheit); } }
private void clearButton_Click(object sender, EventArgs e) { celsiusTextBox.Text = ""; fahrenheitTextBox.Text = ""; }
private void exitButton_Click(object sender, EventArgs e) { // Close the form. this.Close(); } } }
37 38 39 40 41 42 fahrenheit-(cel * (9 / 5)) + 32; fahrenheitTextBox.Text - fahrenheit. ToString(); private void fahrenheitTextBox_TextChanged(object sender, EventArgs e) 45 46 47 48 49 50 51 52 53 54 private void convertButton_Click(object sender, EventArgs e) | if (celsiusTextBox. Focus( celsius Convert.ToDouble(celsiusTextBox.Text); toFahrenheit(celsius) x Exception Unhandled System.FormatException: 'Input string was not in a correct format. 56 57 58 59 60 61 62 63 64 65 View Details Copy Details > Exception Settings private void Form1_Load (object sender, EventArgs e) Temperature Converter Temperature Converter Enter the value of the temperature that you want to convert next to its type name and press the Calculate button Temperature Converter Celsius Temperature Converter Fahrenheit Enter the value of the temperature that you want to convert next to its type name and press the Calculate button. Convert Clear Exit Celsius: Fahrenhet: 80 Convert Clear ExitStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started