CSCI 1300, Section 100
Hints on Assignment 2

1. Do not be confused by the fact that the user may type a line containing 8 or 10 numbers on it.  Remember that a command like

double x;
cin >> x;

will read the next number from the input stream, regardless of whether it is in a buffer (i.e., characters the user previously typed but which have not been processed yet) or whether the program waits for the user to type a line terminated by the "enter" key.   Thus, if the following code is executed:

double x, y, z;
cin >> x;
cin >> y;
cin >> z >> x;

and the user types "1 2 3 4" in response to the first cin, y will be assigned the value 2, z will be assigned the value 3, and x will initially be assigned the value 1 but then its value will change to 4 on the last line of code.

Try out the following code and you'll get a better understanding of how the input stream works:

int i, j;
cout << "Enter first number: ";
cin >> i;
cout << "Enter second number: ";
cin >> j;
cout << "Your numbers are " << i << " and " << j << endl;
When you are prompted to enter the first number, type "123    456".  You'll see that the program does not stop and wait for you to enter a second number, but instead uses what is in the buffer -- the 456.

2. If hint 1 doesn't give you a big clue as to how to handle the input for this program, here is another suggestion.  Have a look at the programs loop3.cxx (see the class examples link on the course home page).  Compile and run this program and when it asks you to enter a number, type
3 4 5 6 -1

Seeing how the program handles this input (it should compute the mean of 3, 4, 5, and 6, which is 4.5) should be illuminating.

3. For part 2 of the assignment, the user will input an ascii code and you will have to print out the character equivalent.  It turns out that converting from an int to a char is simple.  If "i" is the variable that contains the numeric ascii code, and "c" is a char variable, then you can obtain the equivalent char simply by setting

int i;
char c;
c = i;
4. For input pairs beginning with -1 and -2, you should ignore the second number in the pair.

5. For the pairs (-4, n), (-5, n), and (-6, n), which print a square or triangle, the first line of the shape should continue on the output line currently being printed, but the last line should end with a newline.  Thus, a sequence like "4 3 -4 3 1 0 -1 0" should produce:
****   ***
***
***
*
6. There's a typo in the handout and the first sample output should look like
****     *** **