In-Class Exercise

For each question, assume the following declarations:

int num1, num2, num3;
float real1, real2, real3;
For each question, tell what value, if any, will be assigned to each variable, or explain why an error occurs, when the statement is executed with the given input data:
  1. cin >> num1 >> num2 >> num3;
                                          INPUT:  11 22
                                                  33 44
  2. cin >> real1 >> real2 >> real3;
                                          INPUT:  1.1  2   3.3  4
  3. cin >> num1 >> num2 >> num3;
                                          INPUT:  1.1  2   3.3  4
  4. cin >> num1 >> real1 >> num2
        >> real2 >> num3 >> real3;
                                          INPUT:  1.1  2
                                                  3.3  4
                                                  5.5  6

ANSWERS:

  1. num1 = 11, num2 = 22, num3 = 33
  2. real1 = 1.1, real2 = 2.0, real3 = 3.3
  3. num1 = 1, error reading period for num2, all other reads ignored
  4. num1 = 1, real1 = 0.1, num2 = 2, real2 = 3.3, num3 = 4, real3 = 5.5