Lab4_2
This commit is contained in:
47
Lab4_2/Lab4_4_CalebFontenot/Form1.cs
Executable file
47
Lab4_2/Lab4_4_CalebFontenot/Form1.cs
Executable file
@@ -0,0 +1,47 @@
|
||||
namespace Lab3_2_CalebFontenot
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void calculateButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
double miles;
|
||||
double gallons;
|
||||
double mpg;
|
||||
|
||||
// Validate the milesTextBox control.
|
||||
if (double.TryParse(milesTextBox.Text, out miles))
|
||||
{
|
||||
if (double.TryParse(gallonsTextBox.Text, out gallons))
|
||||
{
|
||||
// Calculate MPG.
|
||||
mpg = miles / gallons;
|
||||
|
||||
// Display the MPG in the mpgLabel control.
|
||||
mpgLabel.Text = mpg.ToString("n1");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Display an error message for gallonsTextBox.
|
||||
MessageBox.Show("Invalid input for gallons.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Display an error message for milesTextBox.
|
||||
MessageBox.Show("Invalid input for miles.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void exitButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Close the form.
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user