Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

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 function int main() { }. Statements go between the curly braces of main.
  • 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 line using namespace std; that you'll see online.
  • Text is written in double quotes, numbers without them. C++ can calculate with numbers: std::cout << 5 + 3 prints 8, but std::cout << "5 + 3" prints 5 + 3.
  • std::cout doesn't start a new line by itself. You end a line with std::endl or with \n in 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: description says 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. 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. 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. 3

    Above the statement that calculates 1250 + 300, write a comment that says what this statement does.

Back

8/8

  1. 1. Your First Program
  2. 2. Multiple Lines
  3. 3. Quiz: New Lines
  4. 4. Text and Numbers
  5. 5. Comments
  6. 6. Reading Errors
  7. 7. Quiz: Spot the Mistake
  8. 8. Summary
Next

Try it yourself

Do this exercise right here in your browser. No account needed.