Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C I need to pass two structures into getTotals function and I need to use only pointers, my issue it with the getTotals(emp, totals,

In C I need to pass two structures into getTotals function and I need to use only pointers, my issue it with the getTotals(emp, totals, SIZE) function, but i keep getting this when i try to compile:

[Error] incompatible type for argument 2 of 'getTotals'

[Note] expected 'struct employeeStats *' but argument is of type 'struct employeeStats

I don't understad what it means

HERE IS MY CODE....

#include

/*Constants */

#define SIZE 5

#define STD_HOURS 40.0 /* standard weekly work hours*/

#define TIME_HALF 1.5 /*time and a half*/

/* struct type for an employee */

struct employee

{

char name [20];

int id;

float wage;

float hours;

float overtime;

float gross; ;

};

struct employeeStats{

/*totals*/

float total_wage;

float total_hours;

float total_ot;

float total_gross;

};

/* Function Prototypes */

void getHours (struct employee * ptr, int size);

void printData (struct employee * ptr, int size);

void getGross(struct employee * ptr, int size);

void getOverTime(struct employee * ptr, int size);

void getTotals(struct employee * ptr, struct employeeStats * pts, int size);

void getHours (struct employee * ptr, int size)

{

int i; /* loop index */

for (i = 0; i < size; ++i)

{

printf (" Enter hours for %s, I.D. number %06i: ", ptr->name, ptr->id);

scanf ("%f", &ptr -> hours);

/* move pointer to next employee */

++ptr;

}//end for

}

void getGross(struct employee * ptr, int size){

int i;

for (i = 0; i < size; ++i)

{

if(ptr->hours > STD_HOURS){

ptr->gross = (STD_HOURS * ptr->wage) + ((ptr->overtime * TIME_HALF) * ptr->wage);

}else{

ptr->gross = ptr->hours * ptr->wage;

}

/* move pointer to next employee */

++ptr;

}//end for

}

//////////////////////////////////////////////////////////////////////////////////

void getOverTime(struct employee * ptr, int size){

int i;

for (i = 0; i < size; ++i)

{

if(ptr->hours > STD_HOURS){

ptr->overtime = ptr->hours - STD_HOURS; /*calculating overtimes hours, if there is any*/

}else{

ptr->overtime = 0;

}

/* move pointer to next employee */

++ptr;

}//end for

}

///////////////////////////////////////////////////////////////////////////////////

void getTotals(struct employee * ptr, struct employeeStats * pts, int size)

{

int i;

for(i = 0; i < size; i++){

pts->total_wage += ptr-> wage;

pts->total_hours += ptr-> hours;

pts->total_ot += ptr-> overtime;

pts->total_gross += ptr-> gross;

++ptr;

}

}

void printData (struct employee * ptr, int size)

{

int i; /* loop index */

//printf (" Name\t\tID \t Wage\t Hours OverTime\tGross ");

printf("------------------------------------------------ ");

printf("%s\t\t", "Name");

printf("%6s","Clock#");

printf("%10s","Wage");

printf("%10s","Hours");

printf("%10s","OT:");

printf("%10s ","Gross");

printf("------------------------------------------------ ");

for (i = 0; i < size; ++i)

{

printf ("%s\t%06i \t %5.2f\t %5.1f\t %5.1f\t%5.1f ", ptr->name, ptr->id, ptr->wage, ptr->hours, ptr->overtime, ptr->gross);

/*next employee */

++ptr;

}//end for

}

int main ()

{

/* Array of structures */

struct employee emp [SIZE] = { {"Connie Cobol", 98401, 10.60},

{"Frank Fortran", 526488, 9.75},

{"Mary Apl", 765349, 10.50},

{"Jeff Ada", 34645, 12.25},

{"Anton Pascal", 127615, 10.0}};

struct employeeStats totals = {0,0,0,0};

/* Read in hours for each employee */

getHours (emp, SIZE);

getOverTime (emp, SIZE);

getGross (emp, SIZE);

getTotals(emp, totals, SIZE);

/* Print employee information to the screen */

printData (emp, SIZE);

return (0);

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions