// nestedIfElseDemo3.cpp
//
// Displays the letter grade
// corresponding to a percentage score.
//
// Demonstrates nested if/else with indentation
// standard for a multiway branch, and with
// an else for every if in the nested if/else.
// Also uses return statement where standard.
#include <iostream>
using namespace std;
int main()
{
// Announce purpose of program:
cout << "This program determines the letter grade"
<< " corresponding to a"
<< " percentage score." << endl;
// Ask user for percentage score:
cout << "Enter percentage score:>";
int score;
cin >> score;
// Check range of input:
if ( score < 0 || score > 100 )
{
cout << "You entered " << score
<< ", must be in range [0, 100]." << endl;
return 1;
} // if
// Determine the corresponding letter grade:
char grade;
if ( score >= 90 )
grade = 'A';
else if ( score >= 80 )
grade = 'B';
else if ( score >= 70 )
grade = 'C';
else if ( score >= 60 )
grade = 'D';
else // if ( score < 60 )
grade = 'F';
// Output percentage score and letter grade:
cout << "A score of " << score
<< " receives a grade of "
<< grade << "." << endl;
return 0;
} // function main