Calculating overtime

E

Eric Whittaker

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;

}
 
R

Ron Natalie

Eric said:
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;
}
 
V

Victor Bazarov

Eric said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top