In the above dialog, the user keeps trying interest rates until one is found where the account reaches the million dollar goal. In terms of computer programming, what is the user doing?

A good answer might be:

The user is acting like a result-controlled loop.

Gradually Increasing the Interest Rate

The user is acting like a result-controlled loop, so we could have the program do what the user is doing. Here is an outline of a program that starts the interest rate out at zero percent, then increases it in tenth percent increments until the million dollar goal is reached:

class  MillionDollarInterestRate
{

  public static void main( String[] args ) 
  {
    double initialAmount = 1000.00 ;
    double dollars = 0.0;
    double rate;

    rate = -0.001;    // This is about to be increased to zero
 
    while ( dollars < 1000000 )
    {
       // change to the next rate
       rate = rate + 0.001;

       // compute the dollars after 40 years at the current rate

       . . . . . .

    }

    System.out.println("After 40 years at " + rate*100 
      + " percent interest you will have " + dollars + " dollars" );
  }

}

This is a result controlled loop, because the loop stops only when the interest rate is found that gives us the result we want. The number of times the loop iterates is not explicit in the program.

QUESTION 8:

The skeleton program does not have code for the parts that say "// compute the dollars after 40." How do you expect that this will be done? (Hint: look at the previous version of the program.)