Using a loop of your choice, read information from the console about employees i
ID: 3750917 • Letter: U
Question
Using a loop of your choice, read information from the console about employees in a company. Each employee has an ID (integer) and number of hours worked that week (double) and hourly pay rate (double)
After you read in an employee’s information, you will calculate the salary for that week by multiplying the number of hours worked by the hourly rate. Number of hours and hourly rate should be real numbers with one or two decimal places.
Print a statement clearly indicating the employee ID, number of hours worked, hourly rate and the total salary for that week.
Use a counter variable to keep track of how many employees were processed.
Continue reading information for all employees, processing and printing the information as above until the ID less than or equal to 0. When the ID is 0 or less, you should not be entering hours worked or hourly rate. This means you should read ID separately and continue reading the rest of the data per employee only if ID is > 1.
When the loop is done, print the total number of employees processed by the program and the total salary of all employees.
Print the program and the output
Now add to your program printf statements so that the hours worked and salary will print with two decimal places. Create fixed columns for each piece of data (ID, hors worked, hourly rate and total salary). Numbers should be right adjusted so the dollars and cents line up. Run the program again with the same data and see what the output looks like now. Print the program and the output.
Add an if-else statement in your program to compute tax on the salary. If the salary is less than $300, the tax rate is .03, if salary is between $300 and $350 the tax rate is .04; otherwise the tax rate is .05. Compute the tax by multiplying the salary by the tax rate. Add the tax as another column of your output table. Print the program and the output.
Use these values as input to cover all three tax groups
Hours Hourly Wage 12.5 15.8 15.25 21.2 18.9 20.25Explanation / Answer
ScreenShot
----------------------------------
Program
//Header file for I/O
#include<stdio.h>
int main()
{
//Variables for input and calculations
int eId, processedEmpCount=0;
double workingHrs, hrlyPaymentRate,empSalary=0, totalSalary = 0,tax=0;
//Prompt for employee Id
printf("Enter Employee Id: ");
scanf("%d", &eId);
//Loop processes until employeeid <1
while (eId >= 1) {
//Prompt for working hrs and hrly payement
printf("Enter the hours worked: ");
scanf("%lf", &workingHrs);
printf("enter the hourly payment rate: ");
scanf("%lf", &hrlyPaymentRate);
//Calculate salary
empSalary = workingHrs * hrlyPaymentRate;
//Tax calculation
if (empSalary < 300) {
tax = empSalary * .03;
}
else if (empSalary > 300 && empSalary <= 350) {
tax = empSalary * .04;
}
else if (empSalary > 350) {
tax = empSalary * .05;
}
//count of processing employees
processedEmpCount++;
//Total salary calculation
totalSalary +=empSalary;
//Print details
printf("EmpId WeeklyWorkingHrs HrlyPaymmentrate Salary Tax -------------------------------------------------------------------- ");
printf("%4d %4.2lf $%4.2lf $%4.2lf $%4.2lf ",eId,workingHrs,hrlyPaymentRate,empSalary,tax);
printf("Enter Employee Id: ");
scanf("%d", &eId);
}
//Print total details
printf(" NumberOfEmployeesProcessed= %d TotalEmployeesSalary= $%4.2lf ", processedEmpCount,totalSalary);
return 0;
}
---------------------------------------------------
Output
Enter Employee Id: 1234
Enter the hours worked: 12.5
enter the hourly payment rate: 15.8
EmpId WeeklyWorkingHrs HrlyPaymmentrate Salary Tax
--------------------------------------------------------------------
1234 12.50 $15.80 $197.50 $5.92
Enter Employee Id: 4521
Enter the hours worked: 15.25
enter the hourly payment rate: 21.2
EmpId WeeklyWorkingHrs HrlyPaymmentrate Salary Tax
--------------------------------------------------------------------
4521 15.25 $21.20 $323.30 $12.93
Enter Employee Id: 4785
Enter the hours worked: 18.9
enter the hourly payment rate: 20.25
EmpId WeeklyWorkingHrs HrlyPaymmentrate Salary Tax
--------------------------------------------------------------------
4785 18.90 $20.25 $382.72 $19.14
Enter Employee Id: 0
NumberOfEmployeesProcessed= 3
TotalEmployeesSalary= $903.52
Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.