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 751int score = 75;// First test, for grade A: 75 >= 90 is false2if (score >= 90) { // Skipped because the first condition is false3 cout << "A" << endl;// else if is tested only when the previous condition failed: 75 >= 70 is true4} else if (score >= 70) { // Prints B5 cout << "B" << endl;6}Output
B
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