title: for loop structure
body: <p>This program will calculate the average grade for 4 exams using a for loop by prompting 
  the user for exam grades, one at a time, then calculate the average and display the result. </p>
  
  <pre><code>public class ExamsFor4 {
  
  public static void main(String[] arguments) {
  
  
  int inputNumber; // One of the exams input by the user.
  int sum = 0;     // The sum of the exams.
  int i;       // Number of exams.
  Double Avg;      // The average of the exams.
  
  TextIO.put("Please enter the first exam: ");        // get the first exam.
  inputNumber = TextIO.getlnInt();    
  
  for ( i = 1; i &lt;= 4; i++ ) {  
  
      sum += inputNumber;                 // Add inputNumber to running sum.
      TextIO.put("Please enter the next exam: ");     // get the next exam.   
      inputNumber = TextIO.getlnInt();
  
          if (i == 4) {
              Avg = ((double)sum) / i;
              TextIO.putln();
              TextIO.putln("The total sum for all " + i +" exams is " + sum);
              TextIO.putf("The average for the exams entered is %1.2f.\n", Avg);
              break;
  
          }
  } 
  
  }   // end main ()
  }  // end class ExamsFor4
  </code></pre>
  
  <p>My result:</p>
  
  <pre><code>Please enter the first exam: 100
  Please enter the next exam: 99
  Please enter the next exam: 98
  Please enter the next exam: 97
  Please enter the next exam: 96
  The total sum for all 4 exams is 394
  The average for the exams entered is 98.50.
  </code></pre>
  
  <p>This would be correct except for the last print out of: '<code>Please enter the next exam: 96</code>'
  I tried putting the IF statement between the '<code>sum</code>' line and the <code>TextIO.put 'Enter next exam'</code>, but that isolates it.</p>
  
  <p>Thanks, from a Network Dude trap in a Programmer's world.</p>