calculating overtime

Hello evetybody, I'm new here and i have been having some problems in my C++ class and it's not very easy to get in contact with my professor in a timely manner. So i figured what better place then here. Here is my question i will just post it as the problem is written in the book, but the part that is giving me problems in how do i calculate the overtime. Write a program in which you declare varibles that will hold an hourly wage and number of hours worked. Prompt the user to enter values for hourly rate and hours worked. Compute and disply gross weekly pay, which is calculated as hours times rate for the first 40 hours, plus hours times 1.5 times the rate for any hours over 4. Also display net pay, which is gross pay over $1000, 21% of gross pay if gross pay is not over $1000 but is over $600 and %10 of gross pay if gross pay is not over $600.

This is as much code as i got before i got stuck.

#include<iostream>
using namespace std;
int main()
{
int hourlyWage;
double hoursWorked;
cout << "Please enter your hourly wage " << endl;
cin >> hourlyWage;
cout << "Please enter how many hours worked " << endl;
cin >> hoursWorked;
if(hoursWorked <= 40)
cout << hourlyWage * hoursWorked << endl;
system("pause");
return 0;
}

Any help would be great, and this is an online class so thats why it is hard to get in touch with my professor. Thanks alot.
Well, you are on the right track. What you need to do from here is create an else section. Then, find out how many hours they worked over 40 (their overtime), and store it into a separate variable for calculating. See if you can get going from that.
Thats where im stuck see lets say i make a else if statment for hoursWorked < 40 then how do i times the overtime number by 1.5 or the rate of hours worked? I'm just so confused how to get the overtime hours number by it's self to try and do the math.
This program is giving me so much trouble i have been so stuck on any help would be so great, thanks.
Overtime:
1
2
3
4
else if( (hoursWorked - 40) >= 4) )
{
  cout << "Overtime Pay: " << (hoursWorked -40) * hourlyWage * 1.5 ) << endl;
}


Net pay:
1
2
3
4
5
6
7
8
9
10
11
12
13
int totalPay = normalPay + overTimePay;
if( totalPay >= 1000 )
{
  netPay = totalPay * .21;
}
else if( totalPay >= 600 )
{
  netPay = totalPay * .10
}
else
{
  netPay = someValue
}


This is psuedocode so you will have to translate it into your own code.
I feel so stupid seeing how easy that was. I just couldn't figure it out thanks so very much. I'm sorry fr being such a bother.
Nevermind, I'ms till ahving problems with the over time. Thats the only part of the program thats give me trouble i keep getting a negative number using the above code and i use dev-C++ as my compiler by the way.
Repost all of your code using code tags so we have a clearer picture of what you have.
This is all the code i have so far but if i can get the overtime work i think i can finish the program.

#include<iostream>
using namespace std;
int main()
{
double hourlyWage;
double hoursWorked;
cout << "Please enter your hourly wage " << endl;
cin >> hourlyWage;
cout << "Please enter how many hours worked " << endl;
cin >> hoursWorked;
if(hoursWorked <= 40)
cout << hourlyWage * hoursWorked << endl;
else
if( (hoursWorked - 40) >= 4)
cout << "Overtime Pay: " << (hoursWorked -40 * hourlyWage * 1.5 ) << endl;
system("pause");
return 0;
}
You have to parenthesize your operations. The order of operations is different than you want/expect.

On this line:
cout << "Overtime Pay: " << (hoursWorked -40 * hourlyWage * 1.5 ) << endl;

Change it to this:
cout << "Overtime Pay: " << ( (hoursWorked - 40) * (hourlyWage * 1.5) ) << endl;
Last edited on
ok now it won't even compile. here is my code as i'm trying to compile using Dev-C++. I went back and looked at the posts and can't find anything diffrent from whats posted. I hate being so stuck on one problem for this long.

#include<iostream>
using namespace std;
int main()
{
double hourlyWage;
double hoursWorked;
cout << "Please enter your hourly wage " << endl;
cin >> hourlyWage;
cout << "Please enter how many hours worked " << endl;
cin >> hoursWorked;
if(hoursWorked <= 40)
cout << hourlyWage * hoursWorked << endl;
else
if( (hoursWorked - 40) >= 4) )
cout << "Overtime Pay: " << ( (hoursWorked - 40) * (hourlyWage * 1.5) ) << endl;
system("pause");
return 0;
}



I'm sorry to keep bother you on this issue too.
Extra parenthesis 14 lines down.
if( (hoursWorked - 40) >= 4) )

Take out the parenthesis after the 4.
You are my hero! Thanks again and again for your extended help.
Topic archived. No new replies allowed.