Nested if...else Statements

Nested if...else statements test for multiple cases by placing if...else selection statements inside other if...else selection statements. For example, the following if...else statement displays A for exam grades greater than or equal to 90, B for grades in the range 80 to 89, C for grades in the range 70 to 79, D for grades in the range 60 to 69 and F for all other grades:

if ( studentGrade >= 90 ) // 90 and above gets "A"    cout << "A"; else    if ( studentGrade >= 80 ) // 80-89 gets "B"       cout << "B";    else       if ( studentGrade >= 70 ) // 70-79 gets "C"          cout << "C";       else          if ( studentGrade >= 60 ) // 60-69 gets "D"             cout << "D";           ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.