Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program so that calculates the distance traveled per hour. When the user

ID: 3652730 • Letter: W

Question

Write a program so that calculates the distance traveled per hour. When the user clicks the calculate button, the application should display an INPUT BOX asking the user for the speed of the vehicle in miles-per-hour, followed by another INPUT BOX asking for the amount of time (in hours) that the vehicle has traveled. Then it should use a FOR-NEXT LOOP to display in a LIST BOX the distance the vehicle has traveled for each hour of that time period.


The output in the List Box should look something like this:


Vehicle speed: 40 MPH

Time traveled: 7 hours


Hours Distance Traveled

__________________________

1 40

2 80

3 120

4 160

5 200

6 240

7 280


Explanation / Answer

Option Strict On Public Class frmDistanceCalculator Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click Dim decDistanceTravelled As Decimal Dim decNumberofHoursInput As Decimal = 10 Dim decMPHSpeedInput As Decimal Dim intCounter As Integer = 1 Dim decTotalDistance As Decimal = 0 Dim blnFlag As Boolean Dim strSpeed As String Dim strHours As String Try For intCounter = 1 To CInt(decNumberofHoursInput) strSpeed = InputBox("Please enter your average rate speed in MPH", "Speed") strHours = InputBox("Please enter the number of hours you spent", "Hours") If Not Decimal.TryParse(strSpeed, decMPHSpeedInput) Or Not Decimal.TryParse(strHours, decNumberofHoursInput) Then MessageBox.Show("Values must be numberic.") ElseIf decMPHSpeedInput < 0 Then MessageBox.Show("Values must be greater than zero.") Else 'Calculation decDistanceTravelled = decNumberofHoursInput * decMPHSpeedInput 'Output blnFlag = True lstOutput.Items.Add("Vehicle Speed:" & strSpeed & "MPH" & "Time Travelled:" & ControlChars.CrLf _ & strHours & "hours" & ControlChars.CrLf & "Hours" & "Distance Travelled" & ControlChars.CrLf _ & "******************************************") End If Next Do While decNumberofHoursInput >= 1 decNumberofHoursInput = decNumberofHoursInput - 1 Loop Do While blnFlag = False lstOutput.Items.Add(decNumberofHoursInput.ToString) blnFlag = False Loop 'Total If intCounter = decNumberofHoursInput Then lstOutput.Items.Add("Total Distance: " & decTotalDistance.ToString) End If Catch ex As Exception End Try
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote