Hello. I am having a bit of trouble with this code. Its about making a running log using O(n) (linear) notation but I keep having problems figuring it out. I would appreciate the help for figuring out this code. Can you pleae paste it in eclipse format since that is the software I am using. Thanks. This is the problem: Write a program that: Asks the user for number of runs For each run, ask the user What the distance was in miles (in decimal format, e.g. 3.1 miles is acceptable) What the time was in minutes (in decimal format, e.g. 23.9 minutes is acceptable) Output the average pace (in minutes per mile) of all runs. Please paste the code down below. Thanks.
Hello. I am having a bit of trouble with this code. Its about making a running log using O(n) (linear) notation but I keep having problems figuring it out. I would appreciate the help for figuring out this code. Can you pleae paste it in eclipse format since that is the software I am using. Thanks.
This is the problem:
Write a program that:
- Asks the user for number of runs
- For each run, ask the user
- What the distance was in miles (in decimal format, e.g. 3.1 miles is acceptable)
- What the time was in minutes (in decimal format, e.g. 23.9 minutes is acceptable)
- Output the average pace (in minutes per mile) of all runs.
Please paste the code down below. Thanks.
1. Start the program.
2. Initialize variables:
- totalDistance to 0.0 (total distance of all runs)
- totalTime to 0.0 (total time of all runs)
3. Prompt the user for the number of runs:
- Read and store the number of runs in numberOfRuns.
4. Loop for each run from 1 to numberOfRuns:
a. Display "Run i:" where i is the current run number.
b. Prompt the user for the distance in miles for the current run:
- Read and store the distance in the distance variable.
c. Prompt the user for the time in minutes for the current run:
- Read and store the time in the time variable.
d. Add the distance to totalDistance.
e. Add the time to totalTime.
5. Calculate the average pace:
- Divide totalTime by totalDistance and store it in averagePace.
6. Extract minutes and seconds from averagePace:
- minutes = integer part of averagePace
- seconds = (averagePace - minutes) * 60
7. Format seconds with two decimal places.
8. Display the average pace:
- "Average Pace: minutes minutes formattedSeconds seconds per mile."
9. End the program.
10. The program finishes.
Step by step
Solved in 4 steps with 3 images