ASDV-C-Sharp/MP1/DistanceTraveled_CalebFontenot/Form1.cs

40 lines
1.2 KiB
C#
Executable File

namespace DistanceTraveled_CalebFontenot
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void calculateButton_Click(object sender, EventArgs e)
{
try
{
// Define Vars
double MPH;
double distance5h;
double distance8h;
double distance12h;
// Get data
MPH = double.Parse(mphBox.Text);
// Calculate!
distance5h = MPH * 5; // 5 hours
distance8h = MPH * 8; // 8 hours
distance12h = MPH * 12; // 12 hours
// Print output
label5hr.Text = "The object will have traveled " + distance5h.ToString() + " miles in 5 hours.";
label8hr.Text = "The object will have traveled " + distance8h.ToString() + " miles in 8 hours.";
label12hr.Text = "The object will have traveled " + distance12h.ToString() + " miles in 12 hours.";
}
catch
{
MessageBox.Show("Invalid input!");
}
}
}
}