Loops 7b

Description

The purpose of this challenge is to use the for loop. This challenge uses the concepts of accumulators and loops.

Imagine an online article will be read by x number of people. With each person reading it, your code should estimate the projected total number of minutes the article will have been read by all x people.

Requirements

  1. Declare double variables projected, average, input
  2. Declare and initialize a double variable called total. This variable will be used for accumulating total – what should it be initialized to?
  3. Write a for loop that will loop exactly 10 times, using a counter variable that starts at 1
  4. In this for-loop,
    1. Ask the user to enter a person’s reading time. Use input as the variable for the user’s input. See sample interaction.
    2. Use total to accumulate the total reading time so far
    3. Use average to calculate the average reading time so far
    4. Use projected to calculate the estimated total reading time using the actual total accumulated so far and the estimated reading time for the remaining people using the current average reading time
    5. With each iteration through the loop, display the updated information. See sample interaction.
  5. NOTE and understand that the for-loop pretty much (not completely) stays out of the workings of the main calculations. A for-loop is intended to simply run a fixed number of repetitions. In this example, the counter variable is simply used to identify how many more readers there are. Often, the counter variable is not even used in the loop at all.
  6. For the calculations, note that when the user enters a higher reading time, the average and projections should go up, and conversely should go down if the entered reading time is lower.

DO NOT USE

Any power or exponentiation formulas

Sample Interaction / Output

Enter reading time for person 1: 5
Current average reading time: 5
Current total reading time: 5
Projected total reading time (mins): 50

Enter reading time for person 2: 4.5
Current average reading time: 4.75
Current total reading time: 9.5
Projected total reading time (mins): 47.5

Enter reading time for person 3: 4
Current average reading time: 4.5
Current total reading time: 13.5
Projected total reading time (mins): 45

Enter reading time for person 4: 5
Current average reading time: 4.625
Current total reading time: 18.5
Projected total reading time (mins): 46.25

Enter reading time for person 5: 4.5
Current average reading time: 4.6
Current total reading time: 23
Projected total reading time (mins): 46

Enter reading time for person 6: 5
Current average reading time: 4.66667
Current total reading time: 28
Projected total reading time (mins): 46.6667

Enter reading time for person 7: 4
Current average reading time: 4.57143
Current total reading time: 32
Projected total reading time (mins): 45.7143

Enter reading time for person 8: 5
Current average reading time: 4.625
Current total reading time: 37
Projected total reading time (mins): 46.25

Enter reading time for person 9: 5
Current average reading time: 4.66667
Current total reading time: 42
Projected total reading time (mins): 46.6667

Enter reading time for person 10: 5
Current average reading time: 4.7
Current total reading time: 47
Projected total reading time (mins): 47

LEGEND
PROGRAM OUTPUT
USER INPUT
FROM INPUT

CATALOG ID: CPP-LOOP0007b

Print Requirements