// passOrFail2.cpp
//
// Indicates whether a percentage score
// is passing or failing. The percentage
// score must be in the range [0, 100].
//
// Demonstrates if and if/else statements with
// dependent blocks, and demonstrates return
// statements before end of function.
#include <iostream>
using namespace std;
int main()
{
cout << "This program says whether a percentage"
<< " score is passing or failing." << endl;
// Ask user for percentage score:
cout << "Enter percentage score:>";
int score;
cin >> score;
// Check if score is too low to be a valid score:
if ( score < 0 ) {
cout << "You entered " << score << " is less than 0." << endl;
cout << "It must be in range [0, 100]." << endl;
return 1;
} // if
// Check if score is too high to be a valid score:
if ( score > 100 ) {
cout << "You entered " << score << " is greater than 100." << endl;
cout << "It must be in range [0, 100]." << endl;
return 1;
} // if
// Determine whether score is passing or failing:
if ( score >= 60 ) { // We already know score <= 100
cout << score << " is passing." << endl;
cout << score << " Good for you." << endl;
} else {
cout << score << " is failing." << endl;
cout << score << " You need to either study a lot harder "
<< "or drop the course." << endl;
} // else
return 0;
} // function main