SOURCE FILE: EX0411.CPP
//
// 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 <iostream.h>
int main(void)
{
void instructions(void); // prototypes
int ReadSalary(void);
int OutOfRange(int salary);
int NewSalary(int salary);
int salary; // monthly salary
instructions();
salary = ReadSalary();
if (OutOfRange(salary))
cout << "\nThat salary is out of range\n";
else
cout << "\nThe 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(void)
{
cout << "This program interactively reads a monthly salary\n";
cout << "and computes a new monthly salary. If the salary\n";
cout << "is less than $2000 a month, the raise is $150 a month.\n";
cout << "If the salary is between $2000 and $5000 a month,\n";
cout << "the raise is $250 a month.\n\n";
}
//
// Function to read a salary interactively
// Pre: none
// Post: The salary the user entered has been returned.
//
int ReadSalary(void)
{
int salary; // monthly salary
cout << "Type a monthly salary between $0 and $5000.\n";
cout << "Do not use the dollar sign or commas. ";
cin >> salary;
return salary;
}
//
// Function to return TRUE(1) if salary is out of range
// Range: $0 - $5000
// Pre: salary is an integer.
// Post: A nonzero number (TRUE) has been returned if salary
// is not in range; 0 (FALSE) if it is.
//
int 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);
}