Being Fluent with Information Technology



Box 3.2 - Using Repeated Instruction Execution to Compute DiMaggio's 1950 Batting Average


Figuring a batting average requires that the hits and times at bat for each game be accumulated, so a loop is used to consider the outcome of each game. The processing instructions are conditional on whether DiMaggio played in the game. The "game" is the date value that is changing with each iteration of the loop. Notice that this program assumes DiMaggio batted in at least one game in 1950.

  1. Let the count_of_the_number_of_hits begin at 0.
  2. Let the total_times_at_bat begin at 0.
  3. For each game of the 1950 season beginning with the first,
  4.    if DiMaggio played in the game then
  5.    add DiMaggio's hits in this game to count_of_the_number_of_hits;
  6.    add DiMaggio times at bat in this game to total_times_at_bat;
  7. DiMaggio's batting average is number_of_hits / total_times_at_bat.


    1. Copyright 1999 by the National Academy of Sciences