// nestedIfElseDemo1.cpp
//
// Displays the letter grade
// corresponding to a percentage score.
//
// Demonstrates a nonstandard form of nested
// if/else which, though nonstandard, does have
// an else for every if, thereby guaranteeing
// that all possible cases are covered.

#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 and determine letter grade:
   if ( score < 0 || score > 100 )     // range check
      cout << "You entered " << score
                 << ", must be in range [0, 100]." << endl;
   else  {                // score in range [0, 100]
      // Determine the corresponding letter grade:
      char grade;

      if ( score >= 60 )     // score in range [60, 100]
         if ( score >= 80 )     // score in range [80, 100]
            if ( score >= 90 )     // score in range [90, 100]
               grade = 'A';
            else                   // score in range [80, 90)
               grade = 'B';
         else                   // score in range [60, 80)
            if ( score >= 70 )     // score in range [70, 80)
               grade = 'C';
            else                   // score in range [60, 70)
               grade = 'D';
      else                   // score in range [0, 60)
         grade = 'F';

      // Output percentage score and letter grade:
      cout << "A score of " << score
               << " receives a grade of "
               << grade << "." << endl;
   }  // else

   return 0;
}  // function main