Notes week of Sep 19

iostream-demo.cpp

To try these different demonstrations, rename functions so there’s exactly one called main.

#include <iostream>  // Essential I/O operations
#include <iomanip>   // Used for some I/O operations, like setw below.
using namespace std;

// Justify numbers in a field of some width
int main()
{
    int maxWidth = 9;
    cout.fill('*');
    // What about justification of numbers (left vs right)
    cout << setw(maxWidth) << 13 << endl;
    cout.fill(' ');
    cout << setw(maxWidth) << 7613 << endl;
    cout << setw(maxWidth) << 881225 << endl;
    return 0;
}

int tryVarsAndFormatting()
{
    // Variables store values. The value assigned can change.
    // Every variable has a type: int, float/double, char, string
    float salary = 23586;
    cout.setf(ios::fixed); // Enforce fixed-decimal notation
    cout.precision(2);
    cout << "You make $" << salary << endl;
    cout << "Congrats, you got a 20% raise!" << endl;
    salary = salary * 1.2;
    // cout.precision(2);  // Switches to scientific notation: 2.8e+04
    cout << "Now you make $" << salary << endl;

    return 0;
}


// Our first program
int helloWorld()
{
   cout << "Hello" << "world!" << endl;
   cout << "This is a test";
   cout << 5*11 << "\n";
   return 0;
}