Hi I'm brand new to C++ and am currently doing a lab that has me so stumped. The first part I managed to do correctly with this code
#include <iostream>
using namespace std;
int main( )
{
int hours;
double gross_pay, rate;
cout << "Enter the hourly rate of pay: $";
cin >> rate;
cout << "Enter the number of hours worked,\n"
<< "rounded to a whole number of hours: ";
cin >> hours;
if (hours > 40)
gross_pay = rate*40 + 1.5*rate*(hours - 40);
else
gross_pay = rate*hours;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "Hours = " << hours << endl;
cout << "Hourly pay rate = $" << rate << endl;
cout << "Gross pay = $" << gross_pay << endl;
return 0;
}
Now I need to create a new project in codeblocks to almost do the same thing. However this time after running and entering the hours and pay I need the output to look like this:
Enter your hourly rate of pay:
Enter the number of hours worked:
Hours worked = x
Hourly rate of pay = $xxx.xx
Base pay = $xxx.xx
Overtime pay = $xxx.xx
Gross pay = $xxx.xx
Basically what's being added is the overtime pay and base pay.
your gross_pay = rate*40 + 1.5*rate*(hours - 40); is wrong
setup your overtime which i'm assuming is your 1.5 *rate* (hours- 40) and calculate that (since you need that as an output)
your gross pay should then be either your basepay which is equal to (rate *hours) as long as your hours worked is equal to 40 hours or less. or if you worked more than 40 hours then grosspay equals overtime + basepay
Alright so I've got everything right except for my overtime pay statement. For overtime pay its just listing the amount of overtime made in 1 hour of overtime. For example if I enter $10 hourly wage working 50 hours it'll just list $15 for overtime pay. How can I modify this to make it list the total amount of pay from overtime?
I'm using: cout << "Overtime pay = $" << rate*1.5*(hours > 40) << endl;
since you pretty much figured it out . Here's how I did it
1 2 3 4 5 6 7 8 9 10
int max= 40; // didn't like using 40 so i just created this int to make it cleaner
if (hours <= max)
basepay= rate*hours;
else
{
basepay = max*rate;
overtime = 1.5*rate*(hours - max);
}
gross_pay = basepay+ overtime;