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

double sum = 0, height = 2.0, stop =10, max = 50; int track = 0, num = 0; while

ID: 3773281 • Letter: D

Question

            double sum = 0, height = 2.0, stop =10, max = 50;
            int track = 0, num = 0;
            while (num <= stop)
            {
                sum = sum + height * num;
                if (sum <= max)
                    track++;
                num++;
            }

       num, track
       sum, track
       track, sum
       height, stop

9. (TCO 5) In this code, the variable _____ is a counter and the variable _____ is an accumulator.

            double sum = 0, height = 2.0, stop =10, max = 50;
            int track = 0, num = 0;
            while (num <= stop)
            {
                sum = sum + height * num;
                if (sum <= max)
                    track++;
                num++;
            }

(Points : 5)

Explanation / Answer

In the given code, the variable track is a counter and the variable sum is an accumulator.

Explanation:

The variable track is counter variable that is used to keep track of
number of sum values are found with condition sum <=max
in the while loop

The variable sum is an accumulator that accumulates the sum of
value of sum
and multiplication of num and height
(height *num)

The correct option is track , sum