Small Steps I — Creating with Text and Numbers

Naming a value that will not change

Set a goal of 200 and print how much more is needed from a current score of 80.

What you will learn

const means the initial value will not be changed later. Use it to name a fixed value such as a game's target score.

Try it

Example · example.cpp
void small_main()
{
    const int goal_score = 100;
    int score = 80;
    print(goal_score - score);
}

Assigning a different value to goal_score later causes a compilation error.

In this course, start names with an English letter and use letters, digits, and underscores. Do not include spaces. score and Score are different names. C++ keywords such as int and if cannot be names.

Expected output:

20

Exercise

Set a goal of 200 and print how much more is needed from a current score of 80.

Exercise starter · exercise_starter.cpp
void small_main()
{
    const int goal_score = 100;
    int score = 80;
    print(goal_score - score);
}

Hint

Change the parts of the example that you need.

show solution
void small_main()
{
    const int goal_score = 200;
    int score = 80;
    print(goal_score - score);
}
← Previous lessonNext lesson →