Monday, September 19, 2016

Week 3 PowerPoints

Week 3 PDF

Week 3 PPTX

Resistor colors:

0Black
1Brown
2Red
3Orange
4Yellow
5Green
6Blue
7Violet
8Gray
9White


Week 3 code. This is the code I typed in class.

//
//  main.cpp
//  Sept19
//
//  Created by Mark Brautigam on 9/19/16.
//  Copyright © 2016 Mark Brautigam. All rights reserved.
//

#include <iostream>
using namespace std;

string getString (string s) {
    string returnValue;
    cout << s << ": ";
    cin >> returnValue;
    return returnValue;
}

double getDouble (string s) {
    double returnValue;
    cout << s << ": ";
    cin >> returnValue;
    return returnValue;
}

int getInteger (string s) {
    int returnValue;
    cout << s << ": ";
    cin >> returnValue;
    return returnValue;
}

int main(int argc, const char * argv[]) {
    // insert code here...
    // std::cout << "Hello, World!\n";
    
    int userNumber = getInteger ("Give me a number from 0 to 9");
    /*
     double anotherNumber = getDouble ("Give me a second number");
    cout << "The sum is " << userNumber + anotherNumber << endl;
     */
    /*
    if (userNumber % 2 == 1) {
      cout << userNumber << " is odd." << endl;
    }
    else {
        cout << userNumber << " is even." << endl;
    }
     */
    /*
    if (userNumber == 0) {
        cout << "Black" << endl;
    }
    else if (userNumber == 1) {
        cout << "Brown" << endl;
    }
    else if (userNumber == 2) {
        cout << "Red" << endl;
    }
    else if (userNumber == 3) {
        cout << "Orange" << endl;
    }
    else if (userNumber == 4) {
        cout << "Yellow" << endl;
    }
    else if (userNumber == 5) {
        cout << "Green" << endl;
    }
    else if (userNumber == 6) {
        cout << "Blue" << endl;
    }
    else if (userNumber == 7) {
        cout << "Violet" << endl;
    }
    else if (userNumber == 8) {
        cout << "Gray" << endl;
    }
    else {
        cout << "White" << endl;
    }
     */
    switch (userNumber) {
        case 0 : cout << "Black"; break;
        case 1 : cout << "Brown"; break;
        case 2 : cout << "Red"; break;
        case 3 : cout << "Orange"; break;
        case 4 : cout << "Yellow"; break;
        case 5 : cout << "Green"; break;
        case 6 : cout << "Blue"; break;
        case 7 : cout << "Violet"; break;
        case 8 : cout << "Gray"; break;
        case 9 : cout << "White"; break;
        default : cout << "Not recognized"; break;
    }
    cout << endl;

    return 0;
}




No comments:

Post a Comment