I could really use some help with the question below! Must use C# and please mak
ID: 3833279 • Letter: I
Question
I could really use some help with the question below!
Must use C# and please make it simple as I am a beginner! Also it must be a form application. Thanks a million!!
(Celsius to Fahrenheit and vice versa)
Implement the following Celsius to Fahrenheit conversion (and vice versa)
Use WinForm application.
Use two buttons (C->F and F->C), input Textbox and output label.
You must use integer methods:
a) Method Celsius returns the Celsius equivalent of a Fahrenheit temperature, using thecalculation
c = 5.0 / 9.0 * ( f - 32 );
b) Method Fahrenheit returns the Fahrenheit equivalent of a Celsius temperature, usingthe calculation
f = 9.0 / 5.0 * c + 32;
c) Use the methods from parts (a) and (b) to write an app that enables the user either to
enter a Fahrenheit temperature and display the Celsius equivalent or to enter a Celsius
temperature and display the Fahrenheit equivalent.
d) you MUST validate user for presence of numbers and their range (-100 +800).
e) Add MessageBox for error handling.
f) Use Mnemonics
(Celsius to Fahrenheit and vice versa with radiobauttons and image)
-Same as above but with radio buttons to select which way to convert
-Add a background image.
Explanation / 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 tempacelciusfarenite
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int a=0,b=0, cel=0, fr=0;//two variable for storing Celsius Fahrenheit
private void Form1_Load(object sender, EventArgs e)
{
radioButton1.Checked = true;
textBox1.Text = 0.ToString();
textBox2.Text = 0.ToString();
a = Convert.ToInt32(textBox1.Text);
b= Convert.ToInt32(textBox2.Text);
}
void fun()
{
if (Convert.ToInt16(textBox1.Text) > 800 || Convert.ToInt16(textBox1.Text) < -100)
{
MessageBox.Show("Can not enter more than 800 and less than -100", "validate", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
}
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
textBox1.Enabled = true;
textBox2.Enabled = false;
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked == true)
{
textBox1.Enabled = false;
textBox2.Enabled = true;
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
a = Convert.ToInt32(textBox1.Text);
if (a > 800 || a < -100)
{
MessageBox.Show("Can not enter more than 800 and less than -100", "validate", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
textBox1.Text = "";
}
else if (textBox1.Text != "" && radioButton1.Checked == true)
{
cel = int.Parse(textBox1.Text);
fr =(cel* 9) / 5 + 32;
textBox2.Text = fr.ToString();
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
b = Convert.ToInt32(textBox2.Text);
if (b > 800 || b < -100)
{
MessageBox.Show("Can not enter more than 800 and less than -100", "validate", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
textBox2.Text = "";
}
else if (textBox2.Text != "" && radioButton2.Checked == true )//is textbox has some value and if radiobutton one is checked then only execute below code
{
fr = int.Parse(textBox2.Text);//converting textbox string value to integer
cel = (fr - 32) * 5 / 9;//method for Celsius calculation
textBox1.Text = cel.ToString();
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.