In: Computer Science
C PROGRAM ..... NOT C++
PROGRAM 3 (UPDATE TO TWO PRIOR PROGRAMS FOR REFERENCE OF PRIOR PROGRAM INSTRUCTIONS PLEASE SEE BELOW)
PROGRAM 3
Adjust program II to make use of functions. All the same rules from the previous program specifications still apply, for example input gathering, output formatting and breaking on -1 still apply.
Additional requirements.
Example (Sample input & output for one person)
Enter name: Glenn
Enter hourly rate: 2.00
Enter hours worked: 50
Enter name: -1
Pay to: Glenn
Hours worked: 50.0
Hourly rate: $ 2.00
Gross pay: $110.00
Base pay: $ 80.00
Overtime pay: $ 30.00
Taxes paid: $ 22.00
Net pay: $ 88.00
Total Paid to all employees = $110.00
(The grand total of payments out.)
PROGRAM 1 AND 2 (JUST FOR REFERENCE NO CODE NEEDED)
PROGRAM 1
Payroll application
PROGRAM 2
Payroll 2.0
Update the first program.
The program logic will first load all of the data, until the user enters the max number of records, or they input -1 for one of the fields. After the data is loaded, it will then be processed and output generated.
CODE USED FOR PROGRAM 2:
#include <stdio.h>
#include <string.h>
void main()
{
char name[5][30];
float hourly_rate[5], hours_worked[5];
float n, gross;
for (int i = 0; i < 5; i++)
{
printf("\nEnter the first name: ");
scanf("%s", name[i]);
if (!strcmp(name[i], "-1"))
break;
printf("\nEnter the hourly rate: ");
scanf("%f", &hourly_rate[i]);
if (hourly_rate[i] == -1)
break;
printf("\nEnter the hours worked: ");
scanf("%f", &hours_worked[i]);
if (hours_worked[i] == -1)
break;
}
for (int i = 0; i < 5; i++)
{
if (!strcmp(name[i], "-1"))
break;
if (hourly_rate[i] == -1)
break;
if (hours_worked[i] == -1)
break;
printf("\nPay to: %s", name[i]);
printf("\nHours worked: %f", hours_worked[i]);
printf("\nHourly rate: $%f", hourly_rate[i]);
if (hours_worked[i] > 40)
{
n = hours_worked[i] - 40;
gross = (40 * hourly_rate[i]) + (n * hourly_rate[i] * 1.5);
printf("\nGross pay: $ %f", gross);
printf("\nBase pay: $ %f", 40 * hourly_rate[i]);
printf("\nOvertime pay: $ %f", n * hourly_rate[i] * 1.5);
printf("\nTax paid: $ %f", gross * .20);
printf("\nNet paid: $ %f", gross - (gross * .20));
}
else
{
printf("\nGross pay:$ %f", hourly_rate[i] * hours_worked[i]);
printf("\nBase pay: $ %f", hourly_rate[i] * hours_worked[i]);
printf("\nTax paid: $ %f", hourly_rate[i] * hours_worked[i] *
.20);
printf("\nNet pay: $ %f", (hourly_rate[i] * hours_worked[i]) -
(hourly_rate[i] * hours_worked[i] * .20));
}
}
}
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 <string.h>
// Function Declarations
float calcBasePay(float hours_worked,float hourly_rate);
float calcOverTimePay(float hours_worked,float hourly_rate);
float calcGrossPay(float basepay,float overtime);
float calcTax(float gross);
float calcNetPay(float gross,float tax);
void main()
{
//Declaring variables
int i;
char name[5][30];
float hourly_rate[5], hours_worked[5];
float n, gross,basepay,overtime,tax,netPay,totalPayment=0;
for (i = 0; i < 5; i++)
{
printf("\nEnter the first name: ");
scanf("%s", name[i]);
if (!strcmp(name[i], "-1"))
break;
printf("\nEnter the hourly rate: ");
scanf("%f", &hourly_rate[i]);
if (hourly_rate[i] == -1)
break;
printf("\nEnter the hours worked: ");
scanf("%f", &hours_worked[i]);
if (hours_worked[i] == -1)
break;
}
for (i = 0; i < 5; i++)
{
if (!strcmp(name[i], "-1"))
break;
if (hourly_rate[i] == -1)
break;
if (hours_worked[i] == -1)
break;
printf("\n%-30s%s","Pay to:", name[i]);
printf("\n%-30s%.2f","Hours worked: ", hours_worked[i]);
printf("\n%-30s$ %.2f","Hourly rate:", hourly_rate[i]);
basepay=calcBasePay(hours_worked[i],hourly_rate[i]);
overtime=calcOverTimePay(hours_worked[i],hourly_rate[i]);
gross=calcGrossPay(basepay,overtime);
tax=calcTax(gross);
netPay=calcNetPay(gross,tax);
printf("\n%-30s$ %.2f","Gross pay: ", gross);
printf("\n%-30s$ %.2f","Base pay:", basepay);
printf("\n%-30s$ %.2f","Overtime pay:",overtime);
printf("\n%-30s$ %.2f","Tax paid:", tax);
printf("\n%-30s$ %.2f","Net paid:", netPay);
totalPayment+=gross;
}
printf("\n\nTotal Paid to all employees = $%.2f",totalPayment);
}
// Function which calculate Gross pay
float calcGrossPay(float basepay,float overtime)
{
return basepay+overtime;
}
// Function which calculate Base pay
float calcBasePay(float hours_worked,float hourly_rate)
{
float basePay=0.0;
if(hours_worked<=40)
{
basePay=hours_worked*hourly_rate;
}
else
{
basePay=40*hourly_rate;
}
return basePay;
}
// Function which calculate Overtime pay
float calcOverTimePay(float hours_worked,float hourly_rate)
{
float overTime=0.0;
if(hours_worked>40)
{
overTime=(hours_worked-40)*hourly_rate*1.5;
}
return overTime;
}
// Function which calculate tax
float calcTax(float gross)
{
return gross*0.20;
}
// Function which calculate net pay
float calcNetPay(float gross,float tax)
{
return gross-tax;
}
=====================================
Output:
==================================Thank You