Small Steps I — Creating with Text and Numbers
Calculating and displaying numbers
Print 12 plus 7, then 12 minus 7.
What you will learn
Write numbers without double quotes. + adds and - subtracts. These are operators: symbols for operations.
Try it
Example · example.cpp
void small_main()
{
print(3 + 5);
print(9 - 2);
print("3 + 5");
}
3 + 5 is an expression that calculates the value 8. "3 + 5" is a string containing those exact characters, so it is not calculated.
Expected output:
8
7
3 + 5
Exercise
Print 12 plus 7, then 12 minus 7.
Exercise starter · exercise_starter.cpp
void small_main()
{
print(3 + 5);
print(9 - 2);
print("3 + 5");
}
Hint
Change the parts of the example that you need.
show solution
void small_main()
{
print(12 + 7);
print(12 - 7);
}