Lessons 1–5 · About 60 min per lesson

Compilation, variables and I/O

Work through the complete path from source code to program output.

Lesson breakdown

  1. Lesson 1

    Compile a program with main and print a line with cout.

  2. Lesson 2

    Compare what int, double and string are used to store.

  3. Lesson 3

    Read integers with cin and verify input order.

  4. Lesson 4

    Compare integer division, remainder and floating-point division.

  5. Lesson 5

    Read compiler diagnostics for a missing semicolon or a type mismatch.

Worked example

Read 17 cards and give out sets of 5. Print the number of complete sets and the remainder.

How to solve it

With two int operands, 17 / 5 is 3 and 17 % 5 is 2.

#include <iostream>

int main() {
    int cards;
    std::cin >> cards;
    std::cout << cards / 5 << " " << cards % 5 << "\n";
}

Assignment

Read total seconds and print full minutes and remaining seconds.

Check your result

125 → 2 5; 60 → 1 0; 0 → 0 0.