Need Help Creating A New Output with Codeblocks

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.
Last edited on
your question did not appear. Please try again
Yeah sorry about got my question in there this time.
let me just format it for you first then I'll look at it

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
   #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; 
}
Alright sorry like I said I'm brand new to this whole thing. Appreciate what you're doing.
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
Last edited on
So before I make lines for the overtime and base pay where would they go in between?
For your basepay create an if statement with the condition of working 40 hours or less.

then set up an else statement for your overtime; add a second line to create your max basepay (40* rate); but don't add the two lines together

outside of this if/else statement set up your gross pay (basepay + overtime)
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; 
Topic archived. No new replies allowed.