Write a program that asks an employee how many hours were worked this week. The base pay rate is $12.50 / hr. For overtime hours (over 40), the employee should be paid 1.5 times the base rate (or 0.5 times base rate as a bonus...however you want to see it).
Output 1:
Enter the hours worked for the week as a whole number: [assume user types: 42]
You worked 2 overtime hours
Your total pay this week is $537.5
Output 2:
Enter the hours worked for the week as a whole number: [assume user types: 36]
Your total pay this week is $450
Hints and Notes:
1) There are many ways to do the math here. Use whatever method you are comfortable with, as I assume you’ve calculated this for your own job before.
2) Do NOT use an ELSE for this question. IF only.
#include <iostream>
using namespace std;
int main() {
float rate = 12.5;
int hours;
cout << "Enter the hours worked for the week as a whole number: ";
cin >> hours;
float bonus = 0;
if (hours > 40) {
int overtime = hours - 40;
cout << "You worked " << overtime << " overtime hours" << endl;
bonus = 0.5 * overtime * rate;
}
cout << "Your total pay this week is $" << hours * rate + bonus << endl;
return 0;
}
Comments
Leave a comment