Notes from 9/26

loops.cpp

#include <iostream>
using namespace std;

int main()
{
    int i = 2;
    int s = 0;
    while(s < 17)
    {
        s = s + i;
        i = i + 1;
    }
    cout << i << '\n';
    return 0;
}



int loop4()  // 17 17 17 17 17 17 17 
{
    int i = 2;
    int x = 15;
    while(i < x) 
    {
        cout << i+x << '\n';
        i = i + 1;
        x = x - 1;
    }
    return 0;
}


int loop3()  // 4 6 8 10 12
{
    int i = 2;
    int x = 15;
    while(i < x) 
    {
        i = i + 2;
        cout << i << '\n';
        x = x - 1;
    }
    return 0;
}


int loop2()  // 4 6 8 10
{
    int i = 2;
    int x = 8;
    while(i <= x) 
    {
        i = i + 2;
        cout << i << '\n';
    }
    return 0;
}

int loop1()  // 2 3 4 5 6 7
{
    int i = 2;
    int x = 8;
    while(i < x) 
    {
        cout << i << '\n';
        i = i + 1;
    }
    return 0;
}

months.cpp

#include <iostream>
using namespace std;
int main()
{
    int month = 2;
    int day = 21;

    if(month == 1)
    {
        cout << "January";
    }
    else if(month == 2)
    {
        cout << "February";
    }
    else if(month == 3)
    {
        cout << "March";
    }
    cout  << "\n";

    // New syntax, for an if-else chain where each condition
    // is equality on the same variable.
    switch(month)
    {
        case 1: cout << "January"; break;
        case 2: cout << "February"; break;
        case 3: cout << "March"; break;
    }
    cout << "\n";

    // That "fall-through", when you omit the break,
    // is sometimes useful:
    switch(day)
    {
        case 1: case 21: case 31:
            cout << "st"; break;
        case 2: case 22:
            cout << "nd"; break;
        default:
            cout << "th";
    }
    cout << "\n";

    return 0;
}