COSC 110                                                           Name _____________________
 


Exercise #6

Show what the following loop will display.  Be careful.  Assume no previous output.
Show the display to the right of the statements.  You may use your notes in figuring
out your answer.

int num = 1;

while (num <= 8)
{
    switch (num)
    {
      case 1: cout << "Bill" << endl;
      case 3: cout << "Mary" << endl;
                break;
      case 5: cout << "Anne" << endl;
      case 8: cout << "Fred" << endl;
                break;
      default: cout << "Wait" << endl;
    }
    num++;
}
 
 

COSC 110                                                            Name _____________________
 


Exercise #6

Show what the following loop will display.  Be careful.  Assume no previous output.
Show the display to the right of the statements.  You may use your notes in figuring
out your answer.

int num = 1;

while (num <= 8)
{
    switch (num)
    {
      case 2: cout << "Arthur" << endl;
      case 4: cout << "Ellen" << endl;
                break;
      case 5: cout << "Robert" << endl;
      case 7: cout << "Nina" << endl;
                break;
      default: cout << "Wait" << endl;
    }
    num++;
}
 
 

Discussion Problem

Suppose we wanted to write a C++ program that prompts the person at the keyboard to enter a year as a 4-digit number, with the limitation that the year has to be between 1492 and 1999.  For example, the person might enter 1620.  The program should read in the number and display the year in words (using "hundreds").  For the example, 1620 would be Sixteen hundred twenty.  Similarly, if 1776 is entered, the program should display Seventeen hundred seventy six; or if 1801 is entered, the program should display Eighteen hundred one.  Any year in the given range should be accommodated.  How can such a program be written?
 

Think about this a few minutes.

Then, either ask a question or be prepared to answer one.