Listing 7. Source code for the program named Alice0175f.

Alice0175f's Code

Created by: Dick Baldwin

world

Events

When the world starts
Do:
world.main ( );


Methods

  public void main ( ) {
    Number grade = 0 ; Number sum = 0 ; Number count = 0 ; Number avg = 0 ;
       // Copyright 2007, R.G.Baldwin
  // Illustrates sentinel loop.
  // Do a priming read.
  grade .set( value , ( NumberDialog( question = Enter next grade or -1 ) ) );
  while ( ( grade >= 0 ) ) {
       // Update the sum.
  sum .set( value , ( ( sum + grade ) ) );
  // Get next grade and increment the counter.
  grade .set( value , ( NumberDialog( question = Enter next grade or -1 ) ) );
  count ++
  }
  // Compute and display average grade.
  avg .set( value , ( ( sum / count ) ) );
  ground .say( ( Average grade = + ( avg .toString() ) ) ); duration = 5 seconds
  }