In: Computer Science
In C Programming
Create a payroll program to store and calculate the payroll for a small company as follows: Ask the user for the number of employees and only accept the number if it is between 5 and 40 employees, otherwise prompt the user again and test the input, keep repeating until the user enters an acceptable number.
Create an array of floats that is 4 rows and an number of columns equal to the number of employees in the company. Program parameters are as follows: Create a menu with the following options (use a do-while loop):
A or a to add employee info
D or d to display employee info
T or t to display total payroll
S or s to display the info of all employees
C or c to display the count of employees present in the array
Z or z to exit program
The information for each employee is: employee number, hours worked, pay rate per hour, tax deduction.
Option A or a: ask the user for one employee information at a time and store it in the array.
Please enter employee number: 2190
Please enter hours worked: 32.50
Please enter pay rate: 9.25
Please enter tax rate deduction: 5.50
Option D or d: ask the user for an employee number as integer and display the information for the corresponding employee (cast the employee number in the array to integer and then compare). If employee number does not match, output a msg. indicating “no such employee”. If the employee number is a match, output all the employee information stored in addition to the calculated deduction and salary.
Output sample: Info for employee number: 2190
Hours worked: 32.50Pay rate: $ 9.25
Total earned: $ 300.63
Tax deduction: 5.50 % for an amount of $ 16.53
Paycheck: $ 284.09
Option T or t: calculate and output the sum of the total for the paychecks of all employees.
Option S or s: display the information for all employees in the same format as in option B one employee at a time separated by a line of ------.
Option C or c: Output the number of employees in the array.
Option Z or z: exit the program.
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
=================================
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
// Creating a struct to hold the informatiomn of an employee
data
struct employee
{
int empNo;
double hoursWorked;
double payrate;
double totEarned;
double taxRate;
double taxDeduction;
double payCheck;
};
int main() {
//Declaring variables
int size,i;
char choice;
int count=0;
/* This while loop continues to execute
* until the user enters a valid number
*/
while(1)
{
// Getting the inputs entered by the user
printf("Enter no of employees :");
scanf("%d",&size);
if(size<5 || size>40)
{
printf("** Invalid.Must be between
5 - 40 **\n");
}
else
break;
}
employee emps[size];
/* This while loop continues to execute
* until the user enters either 'Z' or 'z' or valid choice
*/
while(1)
{
//displaying the menu
printf("\nA or a to add employee
info\n");
printf("D or d to display employee
info\n");
printf("T or t to display total
payroll\n");
printf("S or s to display the info
of all employees\n");
printf("C or c to to display the
count of employees present in the array\n");
printf("Z or z to exit
program\n");
//getting the choice entered by the
user
printf("Enter Choice
:");
scanf(" %c",&choice);
//Based on the user choice the
corresponding case will be executed
switch(choice)
{
case 'A':
case
'a': {
if(count<size)
{
//Getting the inputs entered
by the user
printf("Please enter employee
number:");
scanf("%d",&emps[count].empNo);
printf("Please enter hours
worked:");
scanf("%lf",&emps[count].hoursWorked);
printf("Please enter pay
rate:");
scanf("%lf",&emps[count].payrate);
printf("Please enter tax rate
deduction:");
scanf("%lf",&emps[count].taxRate);
// Performing
calculations
emps[count].totEarned=emps[count].hoursWorked*emps[count].payrate;
emps[count].taxDeduction=emps[count].totEarned*(emps[count].taxRate/100);
emps[count].payCheck=emps[count].totEarned-emps[count].taxDeduction;
count++;
}
continue;
}
case 'D':
case 'd':
{
int
index=-1;
int empNo;
printf("Enter employee number :");
scanf("%d",&empNo);
for(i=0;i<count;i++)
{
if(emps[i].empNo==empNo)
{
index=i;
break;
}
}
if(index==-1)
{
printf("no such
employee\n");
}
else
{
// Displaying the employee
info
printf("Info for employee
number: %d\n",emps[index].empNo);
printf("Hours worked:
%.2f\n",emps[index].hoursWorked);
printf("Pay rate: $ %.2f\n",emps[index].payrate);
printf("Total earned: $ %.2f\n",emps[index].totEarned);
printf("Tax deduction: %.2f for an amount of $
%.2f\n",emps[index].taxRate,emps[index].taxDeduction);
printf("Paycheck: $ %.2f\n",emps[index].payCheck);
}
continue;
}
case 'T':
case
't': {
double totPaychecks=0.0;
for(i=0;i<count;i++)
{
totPaychecks+=emps[i].payCheck;
}
printf("Total pay checks of all employees :
%.2f\n",totPaychecks);
continue;
}
case 'S':
case
's': {
// Displaying all employees info
for(i=0;i<count;i++)
{
printf("Info for employee
number: %d\n",emps[i].empNo);
printf("Hours worked:
%.2f\n",emps[i].hoursWorked);
printf("Pay rate: $ %.2f\n",emps[i].payrate);
printf("Total earned: $ %.2f\n",emps[i].totEarned);
printf("Tax deduction: %.2f for an amount of $
%.2f\n",emps[i].taxRate,emps[i].taxDeduction);
printf("Paycheck: $ %.2f\n",emps[i].payCheck);
printf("-----------------------------------\n");
}
continue;
}
case 'C':
case
'c': {
printf("No of employees in the array is
%d\n",count);
continue;
}
case 'Z':
case
'z': {
break;
}
default:{
printf("** Invalid Choice **\n");
continue;
}
}
break;
}
return 0;
}
======================================
======================================
Output:
=====================Could you plz rate me
well.Thank You