Summary
In this lesson, you learned that:
- A program is a series of statements that run one after another, from top to bottom. Before it runs, the compiler checks it and translates it.
- Every program has a frame:
#include <iostream>and the functionint main() { }. Statements go between the curly braces ofmain. - Every statement ends with a semicolon
;. std::cout <<sends what follows to the output. One statement can send several things in a row, each after its own<<. You have to write the spaces between them into the text yourself.std::means "from the standard library". This course doesn't use the lineusing namespace std;that you'll see online.- Text is written in double quotes, numbers without them. C++ can calculate with numbers:
std::cout << 5 + 3prints8, butstd::cout << "5 + 3"prints5 + 3. std::coutdoesn't start a new line by itself. You end a line withstd::endlor with\nin the text.- Comments start with
//and last until the end of the line, or they go between/*and*/. The compiler ignores them. You can also use them to switch code off (comment it out). - The error message
main.cpp:LINE:COLUMN: error: descriptionsays where the mistake is and what is wrong. Always fix the first error first, and run the program again.
In the next lesson, you'll learn to store values in variables and calculate with them.
Instructions
- 1
Before you go on, try it all out on a small task: the final screen of a game.
Below the heading, print the points from both rounds, each on its own line, so that the program prints:
GAME OVER Round 1: 1250 Round 2: 300 - 2
Add a last line,
Total: 1550. But don't write the number 1550 yourself: let C++ add up the points from both rounds,1250 + 300. - 3
Above the statement that calculates
1250 + 300, write a comment that says what this statement does.