Hi Tater,

Thanks for responding, I just tried your suggestions in my code and I am still getting a weird output for Federal Tax. Do you have any other suggestions? I'm trying to grasp this stuff but am having a hard time!!! Attached is the code and new ouput.

Thanks!

MetDude

Code:

#include <stdio.h>
/* Define function for overtime pay */
float calc_ot_pay (float hw, float hr)
{
/* Declare variables */
float ot_pay;
/* Perform calculations for overtime pay */
ot_pay = (hw - 40.0f) * hr * 1.5f;
return ot_pay;
} /* end calc_ot_pay */
/* Define function for federal tax */
float calc_fed_tax (float gp)
{
/* Declare variables */
float fed_tax;
/* Perform calculations for federal tax */
fed_tax = gp * .2f;
return fed_tax;
} /* end calc_fed_tax */
/*Define function for net pay*/
float calc_netpay (float gp, float fed_tax)
{
/*Declare Variables*/
float netpay;
/* Perform calculations for net pay */
netpay = gp - fed_tax;
return netpay;
} /* end netpay */
/* Begin function main */
int main(void)
{
/* Variable Declarations */
float hours_worked = 0, hourly_rate = 0, gross_pay[10], overtime_pay = 0,
federal_tax[10], net_pay[10], sum_gross, sum_tax, sum_net;
int x = 0, num_emp;
char emp_name[10][30];
/* Welcome and prompt for number of employees */
printf ("Welcome to the Payroll Calculator\n");
printf ("\nEnter the number of employees (1-10): ");
scanf ("%i", &num_emp);
printf ("\n");
/* Check to make sure number of employees is between 1-10 */
while (num_emp < 1 || num_emp > 10)
{
printf ("*** Invalid number of employees. Please enter 1 - 10. ***\n");
printf ("Enter the number of employees (1-10): ");
scanf ("%i", &num_emp);
printf ("\n");
} /* end while */
/* Prompt user for the employees name, hours worked, and hourly rate */
for (x = 0; x < num_emp; x++)
{
fflush(stdin);
printf ("Enter the name for employee #%i: ", x + 1);
gets (emp_name[x]);
printf ("Enter the number of hours employee #%i worked: ", x + 1);
scanf ("%f", &hours_worked);
/* Check to make sure hours worked is greater than 0 */
while (hours_worked < 0)
{
printf ("*** Invalid number of hours worked. Please enter greater than 0. ***\n");
printf ("Enter the number of hours employee #%i worked: ", x + 1);
scanf ("%f", &hours_worked);
} /* end while */
printf ("Enter the hourly rate of employee #%i: ", x + 1);
scanf ("%f", &hourly_rate);
printf ("\n");
/* Check to make sure hourly rate is greater than 0 */
while (hourly_rate < 0)
{
printf ("*** Invalid hourly rate. Please enter greater than 0. ***\n");
printf ("Enter the hourly rate of employee #%i: ", x + 1);
scanf ("%f", &hourly_rate);
printf ("\n");
} /* end while */
/* Determine the gross pay */
if (hours_worked > 40)
{
/* Call to function calc_ot_pay to determine overtime */
overtime_pay = calc_ot_pay (hours_worked, hourly_rate);
gross_pay[x] = 40 * hourly_rate + overtime_pay;
} /* end if */
else
{
gross_pay[x] = hours_worked * hourly_rate;
} /* end else */
/* Determine federal tax */
/* Call to function calc_fed_tax to determine tax */
federal_tax[x] = calc_fed_tax (gross_pay[x]);
/* Determine net pay */
/* Call to function calc_net to determine net pay */
net_pay[x] = calc_netpay (gross_pay[x], federal_tax[x]);
/* Keep track of accumalted total of gross pay, net pay,
and federal tax */
sum_tax = sum_tax + federal_tax[x];
sum_net = sum_net + net_pay[x];
sum_gross = sum_gross + gross_pay[x];
} /* end for */
/* Display the results for each of the employees entered */
printf (" Payroll Report\n");
printf (" --------------\n\n");
for (x = 0; x < num_emp; x++)
{
printf ("%s\n", emp_name[x]);
printf ("Gross Pay: $ %10.2f\n", gross_pay[x]);
printf ("Federal Tax: $ %10.2f\n", federal_tax[x]);
printf ("Net Pay: $ %10.2f\n\n", net_pay[x]);
}
/* Display the totals for the report */
printf (" Report Totals\n");
printf (" -------------\n\n");
printf ("Gross Pay: $ %10.2f\n", sum_gross);
printf ("Federal Tax: $ %10.2f\n", sum_tax);
printf ("Net Pay: $ %10.2f\n\n", sum_net);
return 0;
getchar();
} /* end main */