Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. [10pts] Consider the following program, which is supposed to compute the sum of the integers from 1 to 10.
    #include <iostream>
    using namespace std;
    int main()
    {
      int i = 1;
      while(i <= 10)
      {
        int sum = 0;
        sum = sum + i;
      }
      cout << sum << endl;
      return 0;
    }
    a. Why doesn't this program compile? (Note: explain why it doesn't compile as is, not how to fix it!) b. Annotate the code to show how to fix it so that it works properly.
  2. [80pts] Write a program that reads in a product computation of the following form:
    n1 * n1 * n2 * n3 * n4 =
    ... and returns the product of the given ints, along with the number of terms in the product. An example run of your program might look like this (with the user input in red):
    Please enter a product to be computed, followed by an = sign.
    : 4 * 56 * 2 * 7 * 4 =
    The product of the 5 numbers entered is 12544
  3. [10pts] Run your program on input:
    111 * 222 * 333 * 444 * 555 * 666 =
    What's strange about this answer, and what do you think happened?
Turn in a printout of this cover sheet with your answers to the questions, your source code, and a screen capture of your program running the input:
4 * 56 * 2 * 7 * 4 =