I am trying to make a simple distance calculator that outputs the miles traveled over the course of a user defined time at a user defined speed to a list box. I have used a series of IF statements to catch any invalid input. After its loaded I can type invalid input and it functions properly, so I know that the problem has something to do with my if. When I type in proper numbers, the whole program freezes then windows tells me that it has quit responding. I've never had a problem like this before.
int vehicleSpeed;
int hoursTraveled;
int loopCounter = 1;
private void calculateDIstanceButton_Click(object sender, EventArgs e)
{
if (int.TryParse(vehicleSpeedTextbox.Text, out vehicleSpeed))
{
if (int.TryParse(hoursTravledTextbox.Text, out hoursTraveled))
{
while (loopCounter <= hoursTraveled)
distanceCalculationsListBox.Items.Add("The Distance traveled after " + loopCounter + " hour is " + (vehicleSpeed * hoursTraveled));
++loopCounter;
}
else
{
MessageBox.Show("That is not a valid input for time");
}
}
else
{
MessageBox.Show("That is not a valid speed input");
}
}