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
- Lesson 1
Compile a program with main and print a line with cout.
- Lesson 2
Compare what int, double and string are used to store.
- Lesson 3
Read integers with cin and verify input order.
- Lesson 4
Compare integer division, remainder and floating-point division.
- 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.