Previous Lecture lect06 Next Lecture

lect06, Thu 01/24

Relative vs absolute path; `switch` statement

Announcements

Directory Navigation in Linux

Relative Paths

Absolute Paths

Switches

Switch Syntax

#include <iostream>
#include <string>

using namespace std;

int main (){

    char answer = 'z';
    double x = 5;
    int y = 3;

    cout << "5/3 = " << x/y << endl;

    return 0;


    do {
        cout << "Yes or no?" << endl;
        cin >> answer;

        switch(answer)
        {
        case 'Y':
        case 'y':
            cout << "You said yes! " << answer << endl;
            break;
        case 'N':
        case 'n':
            cout << "You said no! " << answer << endl;
            break;
        default:
            cout << "Default " << answer << endl;
            break;
        }
    } while (answer != 'q');

    cout << "Goodbye!" << endl;
    return 0;
}

We didn’t get to talk about integer division in the 630 lecture, but you need to make sure you know how it works.

#include <iostream>
#include <string>

using namespace std;

int main (){
    char answer = 'z';

    do {
        cout << " Yes or no?" << endl;
        cin >> answer;

        switch(answer)
        {
            //When there are two cases one after another, they will both fall through to the same executed statements
            case 'Y':
            case 'y':
                cout << "You said Yes! " << answer << endl;
                break;
            case 'N':
            case 'n':
                cout << "You said No! " << answer << endl;
                break;
            default:
                cout << "default" << endl;
        }
    } while ((answer != 'q') && (answer != 'Q'));

    cout << "Goodbye!" << endl;

    return 0;
}