ASDV-C-Sharp/Lab4_2/Lab4_4_CalebFontenot/Form1.cs

47 lines
1.3 KiB
C#

2022-09-13 15:08:17 +07:00
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();
}
}
}