Name: ____________________________________________________ Alpha: _____________________

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;
}

Why doesn't this program compile? Explain below why it doesn't compile as is (not how to fix it). Then annotate the code above to show how to fix this error (and any other errors) so that the program both compiles and works properly.

2. [85pts] Write a program called 'product' that reads two integers $n_1$ and $n_2$ (with $n_1 \lt n_2$) from the user, and must use a while loop to multiply all the numbers from $n_1$ to $n_2$ (including both $n_1$ and $n_2$) and print out the result. For example, if $n_1=2$ and $n_2=5$, then the result would be $2 \cdot 3 \cdot 4 \cdot 5$, which comes out to 120. Example runs:
$./product Enter two integers: 2 5 Product of all integers between 2 and 5 is 120$ ./product
Enter n: 10 13
Product of all integers between 10 and 13 is 17160
$./product Enter n: 1 12 The product of all integers between 1 and 12 is 479001600  3. [5pts] Consider your program 'product' above. Give the following input: $ ./product
Enter two integers: 1 13

Why do you think your program outputs the result incorrectly?
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 inputs above.