Computer Science, asked by sriiswaryabaimaruthi, 7 hours ago

write a c++ program that,given the number of hours an employee worked and his hourly wage,computes his weekly pay.count any hours over 40 as overtime at time-and-a-half​

Answers

Answered by shivaranjaniks25
3

#include <iostream>

#include <iomanip>

using namespace std;

const int STD_HRS = 40;

const float OVERTIME_MULT = 1.5;

int main()

{

cout << fixed << showpoint;

cout << setprecision(2);

float hours, rate;

cout << "Enter hours worked: ";

cin >> hours;

cout << "Enter rate: ";

cin >> rate;

float regular, overtime;

if ( hours <= STD_HRS )

{

regular = hours * rate;

overtime = 0.0;

}

else

{

regular = STD_HRS * rate;

overtime = (hours - STD_HRS) * rate * OVERTIME_MULT;

}

float pay;

pay = regular + overtime;

cout << "Pay: $" << pay << endl;

return 0;

}

Answered by vishakasaxenasl
0

Answer:

The below C++ Program performs the desired function:

#include <iostream>

using namespace std;

const int STD_HRS = 40;

const float OVERTIME_MULT = 1.5;

int main()

{

float hours, rate, pay;

float regular, overtime;

cout << "Enter the daily hours worked: ";

cin >> hours;

cout << "Enter the rate at which they worked: ";

cin >> rate;

if ( hours <= STD_HRS )

{

regular = hours * rate;

overtime = 0.0;

}

else

{

regular = STD_HRS * rate;

overtime = (hours - STD_HRS) * rate * OVERTIME_MULT;

}

pay = regular + overtime;

cout << "Pay\t" << pay << endl;

return 0;

}

Program Logic:

Let's understand the code above:

  • Our task is to compute the weekly pay of the employees.
  • Since standard working hours and overtime are already fixed in the problem so we have to make them constant.
  • The logic to solving the problem is to know whether the employee has worked equal to or more than the standard working hour.
  • If the employees only have worked for standard working hours or less than that then their overtime will be zero.
  • But those employees who have worked for standard working hours as well as for overtime their pay count will be more than the regular employees.
  • Lastly, we print the amount payable to the employees.

#SPJ2

Similar questions