// // Example 4.11. Interactive program to compute the raise of // a salaried employee. Those that earn less than $2000 a // month get a raise of $150 a month, and those with // salaries between $2000 and $5000 a month receive a raise // of $250 a month. // #include using namespace std; int main() { void instructions(); // prototypes int readSalary(); bool outOfRange(int salary); int newSalary(int salary); int salary; // monthly salary instructions(); salary = readSalary(); if (outOfRange(salary)) cout << endl << "That salary is out of range" << endl; else cout << endl << "The new salary is " << newSalary(salary) << endl; return 0; } // // Function to print instructions on what the program does // Pre: none // Post: Instructions have been displayed. // void instructions() { cout << "This program interactively reads a monthly salary" << endl; cout << "and computes a new monthly salary. If the salary" << endl; cout << "is less than $2000 a month, the raise is $150 a month." << endl; cout << "If the salary is between $2000 and $5000 a month," << endl; cout << "the raise is $250 a month." << endl << endl; } // // Function to read a salary interactively // Pre: none // Post: The salary the user entered has been returned. // int readSalary() { int salary; // monthly salary cout << "Type a monthly salary between $0 and $5000." << endl; cout << "Do not use the dollar sign or commas. "; cin >> salary; return salary; } // // Function to return true if salary is out of range // Range: $0 - $5000 // Pre: salary is an integer. // Post: true has been returned if salary // is not in range; false if it is. // bool outOfRange(int salary) { return ((salary < 0) || (salary > 5000)); } // // Function to return new salary. For salaries < $2000, // raise is $150; for salaries between $2000 and $5000, // raise is $250 // Pre: salary is an integer between 0 and 5000. // Post: The modified salary (previous salary + raise) // has been returned. // int newSalary(int salary) { int raise; // monthly raise in salary if (salary < 2000) raise = 150; else raise = 250; return (salary + raise); }