payroll program using structures
I have a question, on the payroll program which now incorporates structures. I am taking the variables and putting them into structures. I am trying to fix this program it comes as command prompt and asks the hours for each employee after the five employees it doesn't put out the output.
I get errors like "error C2440: 'function' : cannot convert from 'float' to 'float *'"
I have a pic of the program and the source code.
Code:
#include <stdio.h>
#define STD_HOURS 40.0
#define OT_RATE 1.5
#define SIZE 5
float GetHours(int ClockNumber)
{
float Hours;
printf("Enter hours worked for clock %06i: ", ClockNumber);
scanf("%f", &Hours);
return (Hours);
}
float CalcOT(float Hours)
{
/* test to see if any overtime was worked */
if (Hours > STD_HOURS)
return (Hours - STD_HOURS);
else /* no overtime was worked */
return (0.0);
}
float CalcGross(float Hours, float Wage, float OT)
{
float Gross;
/* check for overtime and calculate gross*/
if (OT > 0) {
Gross = (STD_HOURS * Wage) /* regular pay */
+ (OT * OT_RATE * Wage); /* ot pay */
} /* if */
else /* not ot */
{
Gross = Wage * Hours;
} /* else */
return (Gross);
} /* CalcGrossPay */
void PrintOutput(int ClockNumber[], float Wage[], float Hours[], float OT[], float Gross[])
{
int i; /* loop index */
/*prints series for formatted dashes Horizontally*/
printf ("----------------------------------------------------------\n");
/*prints the employee's data header*/
printf ("\tClock# Wage Hours OT Gross\n");
/*Same as the first printf()*/
printf ("----------------------------------------------------------\n");
for (i = 0; i < SIZE; i++) {
printf ( "\t%06li $%5.2f %5.1f %5.1f $%6.2f\n",ClockNumber[i],Wage[i],Hours[i],OT[i],Gross[i]); /*prints the employee's data according to the given precision*/
} /* for */
}
int main()
{
int i;
struct employee
{
int ClockNumber;
float Wage;
float Hours;
float OT;
float Gross;
};
struct employee emps[SIZE] =
{
{98401, 10.60},
{526488, 9.75},
{765349, 10.5},
{634645, 12.25},
{127615, 8.35}
};
/* loop index */
printf ("\tThis is a program to calculate gross pay.\n\n"); /*print the string of characters on the screen*/
/*prompt for the input values from the screen*/
for (i = 0; i < SIZE; i++) {
emps[i].Hours = GetHours(emps[i].ClockNumber);
emps[i].OT = CalcOT(emps[i].Hours);
emps[i].Gross = CalcGross(emps[i].Hours, emps[i].Wage, emps[i].OT);
}
// the printing would make a nice function as well
PrintOutput(emps[i].ClockNumber,emps[i].Wage,emps[i].Hours,emps[i].OT,emps[i].Gross);
return 0;
} /* main */