468,737 Members | 1,790 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,737 developers. It's quick & easy.

Calculating overtime

here's my dilemma, on the program below, i am trying to calculate overtime
pay at time and a half, but instead of only counting the hours after 40, it
counts all hrs at that rate, how can i avoid this? thanks.

// figures hourly wages for employees

#include <iostream>
#include <conio.h>

using std::cout;
using std::cin;
using std::fixed;

#include <iomanip>

using std::setprecision;

//function main begins program execution
int main()
{
int total; // represents salary
int hrs; // represents hours worked
int rte; // represents rate paid
int ovr; // represents overtime pay

total = 0;
ovr = 0;

cout << "Enter hours worked (-1 to end):";
cin >> hrs;

while ( hrs != -1 ) {
cout << "\nEnter hourly rate of the worker:";
cin >> rte;
if ( hrs > 40 );
ovr = ( rte * .5 * hrs );
total = ( hrs * rte + ovr );
cout << "\nSalary is $" << setprecision ( 2 ) << fixed << total;

cout << "\nEnter hours worked (-1 to end:";
cin >> hrs;

if ( hrs < 0 );
break;
}

return 0;

}
Jul 23 '05 #1
2 4807
Eric Whittaker wrote:
here's my dilemma, on the program below, i am trying to calculate overtime
pay at time and a half, but instead of only counting the hours after 40, it
counts all hrs at that rate, how can i avoid this? thanks.

int base_hours = hrs;
int overtime_hours = 0;
if(hrs > 40) {
base_rate = 40;
overtime_hours = hours-40;
}
Jul 23 '05 #2
Eric Whittaker wrote:
here's my dilemma, on the program below, i am trying to calculate overtime
pay at time and a half, but instead of only counting the hours after 40, it
counts all hrs at that rate, how can i avoid this? thanks.
[...]


Forget the code for a minute. Let's just do it on a piece of paper...

If I worked 60 hours, my rate of pay is 25 bookers/hr, how much should I
be paid total? If you figured that I should be paid 1750 bookers, you
are correct. Now, how did you arrive to that number? Now, fix the 'ovr'
and 'total' calculation in your code.

V
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jamie Pittman via AccessMonster.com | last post: by
3 posts views Thread by Jamie Pittman via AccessMonster.com | last post: by
5 posts views Thread by Jamie Pittman via AccessMonster.com | last post: by
reply views Thread by Drum2001 | last post: by
reply views Thread by zhoujie | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.