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();
}
}
}


Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here a new windows forms application in C# is created using visual studio 2017 with name "TempConversion".This application contains a form with name "Form1.cs".Below are the files associated with this form.
1.Form1.cs[Design]

2.Form1.Designer.cs
3.Form1.cs
//namespace
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;
//application namespace
namespace TempConversion
{
public partial class Form1 : Form
{
//declaring variables
double celsius;
double fahrenheit;
int flag;
public Form1()
{
InitializeComponent();
}
//method to convert from fahrenheit to celsius
public void ToCelsius(double fah)
{
//convert to celsius
celsius = (fah - 32) * 5 / 9;
//display celsius temp in the textbox
celsiusTextBox.Text = celsius.ToString("N2");
}
//method to convert from celsius to fahrenheit
public void ToFahrenheit(double cel)
{
//convert to fahrenheit
fahrenheit = (cel * 9 / 5) + 32;
//display fahrenheit temp in the textbox
fahrenheitTextBox.Text = fahrenheit.ToString("N2");
}
//convert button click
private void convertButton_Click(object sender, EventArgs e)
{
//checking value of flag
if (flag == 1)
{
//take user entered celsius temprature and parse it to double
celsius = Convert.ToDouble(celsiusTextBox.Text);
//call method and pass temp in celsius
ToFahrenheit(celsius);
}
//if flag is zero then
else if (flag == 0)
{
//take user entered fahrenheit temprature and parse it to
double
fahrenheit = Convert.ToDouble(fahrenheitTextBox.Text);
//call method and pass temp in fahrenheit
ToCelsius(fahrenheit);
}
}
//Clear button click
private void clearButton_Click(object sender, EventArgs e)
{
//When this button clicked clear textboxes
celsiusTextBox.Text = "";
fahrenheitTextBox.Text = "";
}
//Exit button click
private void exitButton_Click(object sender, EventArgs e)
{
// Close the form.
this.Close();
}
//handling enter evnet for textbox celsiusTextBox
private void celsiusTextBox_Enter(object sender, EventArgs e)
{
flag = 1; //setting value of flag
}
//handling enter evnet for textbox fahrenheitTextBox
private void fahrenheitTextBox_Enter(object sender, EventArgs
e)
{
//setting value of flag
flag = 0;
}
}
}
======================================================
Output : Run application using F5 and will get the screen as shown below
Screen 1 :

Screen 2 :Screen when temp is entered in fahrenheit TextBox

Screen 3 :Screen showing temp in celsius

Screen 4 :Screen showing temp in fahrenheit

Note :In case of both textbox Focus() event returns true hence getting error.
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.
C# I am having trouble this program. So far my temperature converter program is converting temps...
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...
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.”...
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,...
Hi everyone, For my Assignment I have to use C# in order to create a validation form and include the following things to register and validate: Email Address, Username, Password, Retype Password, and a Submit Button. I have figured out some of the code for the Email Address validation: 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 Validation4 { public partial class Form1 : Form { ...
so im trying to make a grade program and idk what im doing wrong actually if someone can help? (heres the lines of code i have so far if its wrong let me know how to fix them Option Strict On Option Explicit On Public Class Form1 Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click Dim lblscore1 As Double Dim lblscore2 As Double Dim lblscore3 As Double lblscore1 = CDbl(Txtscore1.Text) lblscore2 = CDbl(Txtscore2.Text) lblscore3 = CDbl(Txtscore3.Text) lblaverage =...
In java Se8 i am trying to write a program convert temperature
between celsius, fahrenheit and kelvin, but i am stuck at how to
return the proper result without chage the frame, and I cnould not
figure out how to use those three settemp method.
import java. uti1. Arrays public class Temperature different scale names/ public static Stringll scales -Celsius", "Fahrenheit", "Kelvin private double temperature private char scale; public Temperature (double temp temp 273. 15; this. scale-C if (temp <-273....
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...
I need help with this problem in Visual Basic 2012: Write a program that allows the user to specify two numbers and then adds, subtracts, multiplies, or divides them when the user clicks on the appropriate button. The output should give the type of arithmetic performed and the result. Whenever one of the numbers in an input text box is changed, the output text box should be cleared. Also, if the number 0 is entered into the second text box,...
use this code of converting Km to miles , to create Temperature converter by using java FX import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.geometry.Pos; import javafx.geometry.Insets; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.control.Button; import javafx.event.EventHandler; import javafx.event.ActionEvent; /** * Kilometer Converter application */ public class KiloConverter extends Application { // Fields private TextField kiloTextField; private Label resultLabel; public static void main(String[] args) { // Launch the application. launch(args); } @Override public void start(Stage primaryStage) { //...
Use Kilometer Converter application code to write Temperature
Converter application to convert degrees Fahrenheit into degrees
Celsius ((F - 32)*5/9). It needs to be JavaFX
1 import javafx.application. Application; 2 import javafx.stage. Stage; 3 import javafx.scene. Scene; 4 import javafx.scene.layout.HBox; 5 import javafx.scene.layout. VBox; 6 import javafx.geometry.Pos; 7 import javafx.geometry.Insets; 8 import javafx.scene.control.Label; 9 import javafx.scene.control. TextField; 10 import javafx.scene.control.Button; 11 import javafx.event. EventHandler; 12 import javafx.event. ActionEvent; 13 14 ** 15 * Kilometer Converter application 16 17 18 public...