63.9k views
3 votes
You've been hired by Paycheck Penguins to write a C++ console application that determines the pays and taxes on a paycheck. Use a validation loop to prompt for and get from the user a paycheck period in the range A-Z. Each letter corresponds to a two-week period. Use a validation loop to prompt for and get from the user an hourly real-number rate in the range 18-36 $/hour. Use a validation loop to prompt for and get from the user an integer number of hours worked in the range 60-120. Then calculate the gross pay, federal tax, FICA (Social Security and Medicare) tax, state tax, and net pay based on the hourly rate and time worked. Here are the formulas:

gross pay = hourly rate * time worked
federal tax = gross pay * 0.15
FICA tax = gross pay * 0.0765
state tax = gross pay * 0.0435
net pay = gross pay – federal tax – FICA tax – state tax

Format the following eight outputs into two formatted columns:

Paycheck period
Hourly rate
Hours worked
Gross pay
Federal tax
FICA tax
State tax
Net pay

The first column is a left-justified label with units ($/hour, hours, $, etc.) as needed. The second column is a right-justified value. Format all real numbers to two decimal places. Use formatted output manipulators to print the output. Declare and use constants for the federal tax rate, FICA tax rate, gross pay rate, and the column widths. Run the program five times with different inputs for hours worked and hourly rate. What are the results?

1 Answer

4 votes

Answer:

#include<iostream> //i/o library

using namespace std;

int main(){

double hourlyRate = 0;

char paycheckPeriod='a';

while(paycheckPeriod<'A' || paycheckPeriod>'Z'){

cout<<"Enter paycheck period(A-Z): ";

cin>>paycheckPeriod;

}

while(hourlyRate<18 || hourlyRate>36){

cout<<"Enter hourly rate (18-36): ";

cin>>hourlyRate;

}

int hours = 0;

while(hours < 60 || hours > 120){

cout<<"Enter number of hours (60-120): ";

cin>>hours;

}

double grossPay = hourlyRate*hours;

cout<<"Gross Pay: "<<grossPay<<endl;

cout<<"federal tax: "<<0.15*grossPay<<endl;

cout<<"FICA tax: "<<0.0765*grossPay<<endl;

cout<<"state tax: "<<0.0435*grossPay<<endl;

cout<<"Net pay: "<<grossPay-(grossPay*(0.15+0.0765+0.0435));

return 0; //This makes sure that the program terminates

}

Attached is the output

You've been hired by Paycheck Penguins to write a C++ console application that determines-example-1
User Camillia
by
5.6k points