Question: Write the source code that corresponds to the pseudocode Prompt the user for the speed a car is travelling. Use a for loop to create

Write the source code that corresponds to the pseudocode
Prompt the user for the speed a car is travelling. Use a for loop to create a distance chart for the first 5 hours travelled. Validate that rate is at least 0.
Distance = rate * time
Sample Output:
Enter the speed of the car (mph): 60
Hours Travelled Distance Travelled (miles)
------------------------------------------------------------------
160
2120
3180
4240
5300
Pseudocode:
float rate, distance
rate = distance =0.0
int hours
hours =0
rate =-1
while rate <0:
Prompt for rate
if rate <0:
Display Invalid. Rate must be at least 0.
Display Chart
Display Hours Travelled Distance Travelled (miles)
----------------------------------------------------------------------------
for hours in range(1,6):
Calculate distance
distance = hours * rate
Display hours, \t, distance

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!