Question

C# Temp. Converter program.

Create a Celsius and Fahrenheit Temperature Converter application. The application must have 2 Labels (each one of them assigned only to Celsius and Fahrenheit), 2 TextBoxes (each one of them assigned only to Celsius and Fahrenheit), only 1 Convert Button, 1 Clear Button, and 1 Exit Button. Also, 1 Error message label which will display the error messages.

The application should only allow the user to enter the desired temperature just in one of the TextBoxes and display the result on the other TextBox. For instance, when the user enters a temperature in Celsius TextBox, and after clicking the Convert button, the converted temperature should display in a Fahrenheit TextBox or vice versa.

I have most of the application complete I 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.

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)

        {

          

        }

    }

}

Temperature Converter 1回 23 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 Enter the value of the temperature that you want to convent next to its type name and press the Calculate button. Celsius Fahrenheit: Celsius: 13.33 Fahrenheit 56 Convert Clear Exit Convert Clear Exit You should enter data in only one textbox. Press Clear to start over

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:-

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TemperatureConversion
{
public partial class Form1 : Form
{
double celsius;

double Fahrenheit;
public Form1()
{
InitializeComponent();
}

private void btn_exit_Click(object sender, EventArgs e)
{
this.Close();
}

private void btn_clear_Click(object sender, EventArgs e)
{
txtCelsius.Clear();
txtFahrenheit.Clear();
}


public void toCelsius(double fah)
{
  
celsius = (fah - 32) * 5 / 9;
txtCelsius.Text = celsius.ToString();
}

public void toFahrenheit(double cel)
{
  
Fahrenheit = (cel * 9) / 5 + 32;
txtFahrenheit.Text = Fahrenheit.ToString();
}
private void btn_Convert_Click(object sender, EventArgs e)
{
  

if (txtCelsius.Focus() )
{
celsius = Convert.ToDouble(txtCelsius.Text);
toFahrenheit(celsius );
}


if (txtFahrenheit.Focus() )
{
Fahrenheit = Convert.ToDouble(txtFahrenheit.Text);
toCelsius(Fahrenheit);
}

}

private void Form1_Load(object sender, EventArgs e)
{
this.ActiveControl = lblCelsius;

}
}
}

If you find any difficulty with the code, please let know know I will try for any modification in the code. Hope this answer will helps you. If you have even any small doubt, please let me know by comments. I am there to help you. Please give Thumbs Up,Thank You!! All the best

Add a comment
Know the answer?
Add Answer to:
C# Temp. Converter program. Create a Celsius and Fahrenheit Temperature Converter application. The application must have...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C# Temperature Converter Application: I have most of the application complete I just need only help...

    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.”...

  • C# I am having trouble this program. So far my temperature converter program is converting temps...

    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...

  • C# Windows Form Application (CALCULATOR): (This is the instruction below): Windows Calculator that will going to...

    C# Windows Form Application (CALCULATOR): (This is the instruction below): Windows Calculator that will going to create a Windows Form Application that will mimics a calculator. This is the screenshot how it shouldl look like. Calculator It should have a textbox and the following buttons: + Addition - Subtraction * Multiplication / Division = Equals (Will perform the final calculation) C Clear (Will clear the text box) There will be no maximize or minimize buttons. The rules are these: 2...

  • Question: Fahrenheit To Celsius Temperature Converter GUI Assignment Write A GUI To... java Fahrenholt to Celsius...

    Question: Fahrenheit To Celsius Temperature Converter GUI Assignment Write A GUI To... java Fahrenholt to Celsius Temperature Converter GUI Assignment Write a Gul to convert Fahrenheit temperatures to Celsius temperatures and has the following appearance: Com Convert It must include the following foatures • The frame we must say 'Fahrenheit to Celsius Temperature Converter • A border layout will be used for the GUI • The JLabelite of the GUI wil suy Fahrerholt to Celsius Temperature Converter and be in...

  • Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin...

    Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin Newton Your program should take a character which represents the temperature to convert from and a value to be converted to using the following specification: C - Celsius K - Kelvin N - Newton In addition your program should take in the following character to exit the program: X - eXit the program The numeric input for your program should be of type double....

  • Need help with develop Visual C# Exercise 4-3 form to display the Fahrenheit temperature and corresponding...

    Need help with develop Visual C# Exercise 4-3 form to display the Fahrenheit temperature and corresponding Celsius temperature for Fahrenheit temperatures ranging from -40 to +40 degrees, at increments of 10. Use a for loop. The conversion formula is Celsius (Fahrenheit - 32) * 5/9. I ran the following but nothing is displaying in my listbox. I am not familiar with Form1_load, see below. I am not sure how to create in my form. Help please private void Form1_Load_Click(object sender,...

  • This program will take the user's input as a temperature in degrees Fahrenheit. The user will...

    This program will take the user's input as a temperature in degrees Fahrenheit. The user will then click a radio button indicating whether a table of temperatures, starting with the entered value, will be displayed in increments of 5 degrees F or 10 degrees F. When a submit button is clicked your code will display a HTML table of temperature values. The first column will be temperatures in degrees Fahrenheit, given in increments of 5 or 10 degrees F, depending...

  • Program using visual basic.net You will create a very simple two numbers calculator with save options;...

    Program using visual basic.net You will create a very simple two numbers calculator with save options; here is the specifications for the application. Create a form divided vertically in two halves with right and left panels 1- In the left panel you will create the following control, the label or the value of the control will be in "" and the type of the control will in [] a- "First Number" [textbox] b- "Second number" [texbox] c- "Result" [textbox] -...

  • JavaFX Programming Develop a temperature converter GUI JavaFX application that consists of two labels and two...

    JavaFX Programming Develop a temperature converter GUI JavaFX application that consists of two labels and two text fields. Typing a temperature into the Celsius field and then pressing the "Enter" key causes the equivalent Fahrenheit temperature to appear in the Fahrenheit field and vice versa. Temperature Converter Celsius 100 Fahrenheit 212.0 Typing a non-numeric value into either field causes the following error dialog to appear: Message Error, input must be numerical OK Formulas are simple: Celsius to Fahrenheit F =...

  • FOR PYTHON Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice...

    FOR PYTHON Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom functionc_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT