Notes week of Oct 10

switch-time.cpp

// Demonstrating switch for time program (p5)
#include <iostream>
using namespace std;
int main()
{
    int hour12 = 2;  // In 12-hour time, range is 1-12
    // Print hour12 as an English word.
    switch(hour12) {
    case  1: cout << "one";   break;
    case  2: cout << "two";   break;
    case  3: cout << "three"; break;
    case  4: cout << "four";  break;
    case  5: cout << "five";  break;
    default:
        cout << "Error";
    }
    cout << endl;

    // Write morning, afternoon, or evening
    // corresponding to hour.
    int hour24 = 18;
    switch(hour24) {
    case 0:
        cout << "midnight";
        break;
    case 12:
        cout << "noon";
        break;
    case 13: case 14:
    case 15: case 16: case 17:
        cout << "afternoon";
        break;
    case 18: case 19: case 20:
    case 21: case 22: case 23:
        cout << "evening";
        break;
    default:
        cout << "morning";
    }

    return 0;
}