1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

/////////////////////////////////////////////////////////////////////////
// Employee Overtime Pay Calculator  by Owlie53  <http://53media.net>//
/////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <conio.h>
#include <vector>
using namespace std;
// This initializes the array that stores all of out overtime hour points
// Then loads it in to a Vector so we can have the control we need over it
// This is a good solution if you don't want to use other outside libraries like Boost, etc
// This array holds all of hour overtime hour tiers
static const int otHoursArray[] = {100, 120, 150};
// It is then converted in to a vector since we need to know the size
// There are a few ways to accomplish this. I chose converting to a vector.
// This also saves us the time of declaring a vector, and then pushing each value in.
vector<int> otHours(otHoursArray, otHoursArray + sizeof(otHoursArray) / sizeof(otHoursArray[0]));
// Multidimensional Employee Pay Scale Array
int payScale[3][3] = {
{}, // We leave this array blank to make accessing the payscales more literal and more simple
{100, 150, 175}, // Rank 1 Employee Pay Scale
{80, 100, 125} // Rank 2 Employee Pay Scale
};
// This is the declaration for our overtime calculator function
// It will be pass the RANK of the employee, and the amount of OVERTIME HOURS accrued
int calc(int grade, int hours);
// Variable Initialization
int grade; // Employee Grade Identifier. This will correspond to our payScale array
int hours; // The total number of hours the employee has worked
int main(int argc, char ** argv) {
// The first thing we need to do is get the user input
cout << "Enter employee grade (1  2): ";
cin >> grade;
cout << endl;
cout << "Enter employee work hours: ";
cin >> hours;
cout << endl;
// Now let's pass these values to our calculator function and get our output
cout << "Total Overtime Payment: $" << calc(grade, hours) << ".00" << endl;
getch();
return 0;
}
int calc(int grade, int hours) {
int totalPayout = 0; // This will hold our number for the total amount being paid to the employee
int tempHold; // This will hold a temp value to keep track of hour hours
// Since we know we're not paying out for any hours under 'minHours'
// We can immediately subtract minimum ammount of hours needed to rate overtime from the total hours
hours = otHours[0]; // Subtract the first element in our otHours array (the minimum hours needed) from the total hours worked.
// If the amount of hours worked is now zero or less, specify that no payment is due
if(hours < 1) {
return 0;
} else {
// Now lets break down the hours and pay out accordingly
// Initialize a counter
int count = 0;
// While we're within the scope of hour overtime pay scale
while(hours > 0 && count < (otHours.size()  1)) {
// Set tempHold to the difference between the pay scales
tempHold = (otHours[count + 1]  otHours[count]);
//cout << endl << tempHold << endl;
if(hours >= tempHold) {
totalPayout += tempHold * (payScale[grade][count]);
hours = tempHold;
//cout << endl << payScale[grade][count] << "  " << totalPayout << "  " << hours << endl;
} else if (hours < tempHold) {
totalPayout += hours * (payScale[grade][count]);
hours = tempHold;
//cout << endl << payScale[grade][count] << "  " << totalPayout << "  " << hours << endl;
}
count++;
}
// Now that we've calculated the pay for every hour within our payscale
// The remainder (anything over the maximum amount of hours given in the array)
// Will be calculated and added to the total amount.
if(hours > 0) {
totalPayout += hours * (payScale[grade][count]);
hours = hours;
}
return totalPayout;
}
}
 