231k views
1 vote
A(n) __________ variable keeps a running total.

constant valued
counter
sentinel
accumulator

User Dtrunk
by
7.9k points

1 Answer

3 votes

Final answer:

An accumulator variable is used in programming to keep a running total, often within a loop. It differs from a counter, sentinel, or constant by accumulating a sum or result each time the loop iterates.

Step-by-step explanation:

A accumulator variable keeps a running total. In programming, an accumulator is a variable that is used to collect a sum or other aggregate result during a loop. Each iteration of the loop typically adds or subtracts a value to the accumulator.

This is in contrast to a counter, which generally increments by one during each iteration. A sentinel value is used to signify the end of a data set or to signal that a loop should end. A constant is a value that does not change during the execution of a program.



For example, in a loop that calculates the total score from a list of individual scores, the accumulator would start at zero and then sum up the scores as the loop progresses:

  • accumulator = 0
  • For each score in the list:
  • accumulator += score

By the end of the loop, the accumulator will hold the total sum of all the scores.

Therefore, the correct answer is accumulator.

User Radesix
by
7.4k points