Final answer:
This program requests the user to input a vehicle's speed and the amount of time it has traveled, and then calculates and displays the distance traveled each hour using a loop. It demonstrates the concept of average speed in a programming scenario.
Step-by-step explanation:
The task here involves writing a simple program that calculates the distance traveled by a vehicle using the formula distance = speed × time. A user provides the speed of the vehicle in miles per hour and the time it has been traveling for, and the program must output the distance for each of the hours traveled. This demonstrates the practical application of average speed calculations in a programming context.
- Ask the user for the vehicle's speed (in miles per hour).
- Ask the user for the hours traveled.
- Use a loop to calculate the distance the vehicle has covered for each hour.
- Display the outcome in the format given, with hours and the corresponding distance traveled.
The example calculation is as follows: If a vehicle travels at 40 mph for 3 hours, then the distance for each hour is: Hour 1: 40 miles, Hour 2: 80 miles, Hour 3: 120 miles. This is repeated for the time period entered by the user.