Question
C# Temperature Converter Application: I have most of the application complete I just need only help with error messages. My instructor wants me to show
C# Temperature Converter Application:
I have most of the application complete I just need only help with error messages.
My instructor wants me to show four error messages inside an error message label (not a message box) and all of the error messages should appear inside error message label. The four error messages should appear when:
1: User enters data inside both Celsius and fahrenheit text boxes: You should enter data in only one textbox. Press Clear to start over.
2: User leaves text boxes empty and tries to convert: You must enter the temperature that you want to convert. Press Clear to start over.
3: User enters any character that is not a number: "Characters are invalid. Press clear to start over."
4: User enters data below absolute zero (If the Celsius temperature is less than -273.15, Fahrenheit less than -459.67): "You entered an invalid data. Press clear to start over."
So far, I managed to get only 1st error message work and not being able to figure out the rest. Please help me. Attached is the code and screenshot of the error message I managed to figured out. I need help with error messages 2 to 4.
public partial class Form1 : Form
{
double celsius;
double fahrenheit;
int flag;
public Form1()
{
InitializeComponent();
}
public void ToCelsius(double fah)
{
celsius = (fah - 32) * 5 / 9;
celsiusTextBox.Text = celsius.ToString("N2");
}
public void ToFahrenheit(double cel)
{
fahrenheit = (cel * 9 / 5) + 32;
fahrenheitTextBox.Text = fahrenheit.ToString("N2");
}
private void convertButton_Click(object sender, EventArgs e)
{
if (celsiusTextBox.Text != "")
{
if (fahrenheitTextBox.Text != "")
{
messageLabel.Text = "You should enter data in only one textbox. Press Clear to start over.";
}
}
if (flag == 1)
{
celsius = Convert.ToDouble(celsiusTextBox.Text);
ToFahrenheit(celsius);
}
else if (flag == 0)
{
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)
{
this.Close();
}
private void celsiusTextBox_TextChanged(object sender, EventArgs e)
{
flag = 1;
}
private void fahrenheitTextBox_TextChanged(object sender, EventArgs e)
{
flag = 0;
}
private void messageLabel_Click(object sender, EventArgs e)
{
}
}
}
lemperature Converter Temperature Converter Enter the value of the temperature that you want to convert next to its type name and press the Calculate buttor. Temperature Converter Enter the value of the temperature that you want to convert next to its type name and press the Calculate button. Celsius: Fahrenheit: Celsius 13.33 Fahrenhet 56 Convert Clear Exit Convert Clear Ext You should enter data in only one textbox. Press Clear to start overStep 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