4.23 (Financial application: payroll)Write a program that reads the following information and prints a payroll statement:Employee’s name (e.g., Smith)Number of hours worked in a week (e.g., 10)Hourly pay rate (e.g., 9.75)Federal tax withholding rate (e.g., 20%)State tax withholding rate (e.g., 9%)A sample run is shown below:Enter employee's name: SmithEnter number of hours worked in a week: 10Enter hourly pay rate: 9.75Enter federal tax withholding rate: 0.20Enter state tax withholding rate: 0.09Employee Name: SmithHours Worked: 10.0Pay Rate: $9.75Gross Pay: $97.5Deductions:Federal Withholding (20.0%): $19.5State Withholding (9.0%): $8.77Total Deduction: $28.27Net Pay: $69.22Requirement:Requirements: Input and output must match the format provided in the exercise sample runsCurrency must be displayed properly:You must have a dollar sign ($) and 2 places after the decimal (dollars and cents)You must use printf rather than the goofy trick from earlier chaptersAppropriate selection logic must be used to validate user input. You should enforce the following assumptions:Assumption: all text input is non-emptyAssumption: all inputs are non-negativeAssumption: there is no overtime pay (hours worked must be no more than 40)Assumption: tax withholding rates are between 0.0 - 1.0If validation fails for any input:Output a meaningful error message. This isn't shown in the samples, so create your own messages. The messages should indicate the nature of the error/what was expected.Execution must not continue if incorrect input is encountered - use the appropriate method to terminate the program at that point

Question
Asked Mar 12, 2019
369 views

4.23 (Financial application: payroll)

Write a program that reads the following information and prints a payroll statement:

Employee’s name (e.g., Smith)
Number of hours worked in a week (e.g., 10)
Hourly pay rate (e.g., 9.75)
Federal tax withholding rate (e.g., 20%)
State tax withholding rate (e.g., 9%)


A sample run is shown below:
Enter employee's name: Smith
Enter number of hours worked in a week: 10
Enter hourly pay rate: 9.75
Enter federal tax withholding rate: 0.20
Enter state tax withholding rate: 0.09
Employee Name: Smith
Hours Worked: 10.0
Pay Rate: $9.75
Gross Pay: $97.5
Deductions:
Federal Withholding (20.0%): $19.5
State Withholding (9.0%): $8.77
Total Deduction: $28.27
Net Pay: $69.22

Requirement:

Requirements

  • Input and output must match the format provided in the exercise sample runs
  • Currency must be displayed properly:
    • You must have a dollar sign ($) and 2 places after the decimal (dollars and cents)
    • You must use printf rather than the goofy trick from earlier chapters
  • Appropriate selection logic must be used to validate user input. You should enforce the following assumptions:
    • Assumption: all text input is non-empty
    • Assumption: all inputs are non-negative
    • Assumption: there is no overtime pay (hours worked must be no more than 40)
    • Assumption: tax withholding rates are between 0.0 - 1.0
  • If validation fails for any input:
    • Output a meaningful error message. This isn't shown in the samples, so create your own messages. The messages should indicate the nature of the error/what was expected.
    • Execution must not continue if incorrect input is encountered - use the appropriate method to terminate the program at that point
check_circle

Expert Answer

Step 1

C code

#include<stdio.h>
#include<string.h>
 
int main(){
char employeeName[20]="";
double hoursWorked=0.0;
double hourlyPayRate=0.0;
double federalTaxRate=0.0;
double stateTaxRate=0.0;
double grossPay=0.0;
double federalWithholding=0.0;
double stateWithholding=0.0;
double totalDeductions=0.0;
double netPay=0.0;
printf("Enter employee's name: ");
 
scanf("%s", employeeName);
if(strcmp(employeeName,"")==0){
printf("Employee name cannot be empty.");
return -1;
}
printf("Enter number of hours worked in a week: ");
 
scanf("%lf",&hoursWorked);
if(hoursWorked<0.0){
   printf("Hours worked cannot be negative.");
return -1;
}
if(hoursWorked>40.0){
   printf("Hours worked cannot be more than 40.");
return -1;
}
printf("Enter hourly pay rate: ");
 
scanf("%lf",&hourlyPayRate);
if(hourlyPayRate<0.0){
   printf("Hourly pay rate cannot be negative.");
return -1;
}
    printf("Enter federal tax withholding rate: ");
    
    scanf("%lf",&federalTaxRate);
    if(federalTaxRate<0.0){
   printf("Federal tax rate cannot be negative.");
return -1;
}
if(federalTaxRate>1.0){
   printf("Federal tax rate cannot be greater than 1.0.");
return -1;
}
printf("Enter state tax withholding rate: ");
 
    scanf("%lf",&stateTaxRate);
    if(stateTaxRate<0.0){
   printf("State tax rate cannot be negative.");
return -1;...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: Question: Write a function to display a pattern as follows: 1 2       1 ... ... n       n-1         ...

A: Solution:The python program has the following algorithm:In the displayPattern() function,Declare and...

question_answer

Q: This is for pygame Text Class The Text class inherits from Drawable and it will be used to display t...

A: Instructions for the Text class:Import the Drawable class and pygame module.Create a class Text and ...

question_answer

Q: Develop pseudocode for the problem of reading in an arbitrary number of DNA (deoxyribonucleic acid) ...

A: PseudocodeCreate a dictionary data structure to store the DNA base and the complementary base as ser...

question_answer

Q: Write a program that coverts a zip code to a bar code. The bar codes use large and small bars. We wi...

A: Solution:#Define the functiondef checksum(zip):    #Declare the empty variable    sum = 0    #Loop e...

question_answer

Q: CHALLENGE 1.24: Read multiple user inputs. ACTIVITY Write two scnr.nextint statements to get input v...

A: Given below is the program to get input values for month and year and write the output value as a mo...

question_answer

Q: Explain the following error message. $ lsabc abd abe abf abg abh$ rm abc ab*rm: cannot remove ‘abc’ ...

A: “rm” command: This command is used to removes each specified file on the command line.For example, i...

question_answer

Q: Write a grammar for the language consisting of strings built only of theletters aand b. The strings ...

A: The given language L contains the strings that have infinite number of letters but the strings must ...

question_answer

Q: This is C++ my programming lab 11.7: Customer AccountsWrite a program that uses a structure to store...

A: Declare the structure Customer_Accounts with the required data fields. Also, declare an array of 20 ...

question_answer

Q: 5-8) (Find the highest score) Write a program that prompts the user to enter the number of students ...

A: Java program to find the highest score of the student is as follows: