Else If Chain in C++

Level 2104 keystrokes

Checks conditions in order with if and else if: score (75) is not 90 or more but is 70 or more, so B is printed.

C++ code

// Initializes score with 75
1int score = 75;
// First test, for grade A: 75 >= 90 is false
2if (score >= 90) {
// Skipped because the first condition is false
3 cout << "A" << endl;
// else if is tested only when the previous condition failed: 75 >= 70 is true
4} else if (score >= 70) {
// Prints B
5 cout << "B" << endl;
6}

Output

B
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.

  • <× 8
  • "× 4
  • ;× 3
  • =× 3
  • (× 2
  • )× 2
  • {× 2
  • }× 2
  • >× 2

More C++ examples at level 2

← C++ typing practice