C++ Design and create a program to calculate the total wages for an employee. An
ID: 3666414 • Letter: C
Question
C++
Design and create a program to calculate the total wages for an employee. An employee is paid $10 per hour for the first 40 hours. The employee is paid $15 per hour for every hour greater than 40 hours and up to 50 hours. The employee is paid $20 per hour for any hours above 50 hours. The program will ask the user to enter the total number of hours (double), and the program will calculate the total wages (show 2 digits to the right of the decimal point.) If the user enters an invalid number of hours (hours <= 0), then display an error message and terminate the program (use “return 0;” to terminate pgm). Pick good test cases. Include output for all test cases . (Do not compute taxes, just total gross wages)
Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double input;
cout << "Please enter input : :";
cin >> input;
if(input <= 0){
cout << "You have entered invalid input : "<<input;
cout << "Please enter valid input";
return 0;
}
double amount = 0;
if(input-40 > 0){
amount += 40*10;
input = input - 40;
if(input -10 > 0){
amount += 10*15;
input = input -10;
if(input > 0){
amount += (input * 20);
}
}else{
amount += input*15;
}
}else {
amount = input * 10;
}
cout << "Total : "<<setprecision (2) << fixed << amount;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.