Subtraction Assignment in C++

Level 273 keystrokes

Subtracts 25 and then 30 from balance with -=, so 100 becomes 45, and prints 45.

C++ code

// Initializes the balance with 100
1int balance = 100;
// balance -= 25 means balance = balance - 25: 100 - 25 = 75
2balance -= 25;
// Subtracts 30 more: 75 - 30 = 45
3balance -= 30;
// Prints the remaining balance, 45
4cout << balance << endl;

Output

45
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this C++ code and how often they appear.

  • ;× 4
  • <× 4
  • =× 3
  • -× 2

More C++ examples at level 2

← C++ typing practice