Please help c++ code. Thanks! The function paycheck is a void function that calc
ID: 3883280 • Letter: P
Question
Please help c++ code. Thanks!
The function paycheck is a void function that calculates the amount to be paid to an employee based on the hours worked and rate per hour. The formula for calculating the amount to be paid is as follows: for the first 40 hours, the rate is the given, for hours over 40, the rate is 1.5 times the given rate. The function receives as a parameters an integer value(number of hours worked) and the rate per hour. It should return to the calling program a floating point value(the amount to be paid), which is also passed as a parameter. Write the function. Use as formal parameters an integer hrs(number of hours worked), a floating point value rate (rate per hour) and a reference parameter amnt.
Explanation / Answer
Below is your program . Bold part is the required function. Let me know if you have any issue: -
#include<iostream>
using namespace std;
void payCheck(int hrs, double rate,double* amnt) {
if (hrs > 40) {
*amnt += ((hrs - 40) * rate) * 1.5;
*amnt += 40 * rate;
} else {
*amnt = hrs * rate;
}
}
int main() {
double amount = 0;
payCheck(180,12.65,&amount);
cout<<"Payment for 180 hours at $12.65 per hour is "<<amount<<endl;
return 0;
}
Sample Run: -
Payment for 180 hours at $12.65 per hour is 3162.5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.