RE: C program question
- From: "Ken Perry" <whistler@xxxxxxxxxxxxx>
- To: <programmingblind@xxxxxxxxxxxxx>
- Date: Sat, 27 Oct 2007 21:20:23 -0700
emp.clock
Where you have
struct emp
You should define the structure like
struct Employee{
int Clock;
float wage;
float hoursWorked;
}
Where you have
struct employee emp(5);
You should have
Struct Employee emp[5];
Then the rest should work better or at least give you errors you understand.
Ken
-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of John Miller
Sent: Saturday, October 27, 2007 5:01 AM
To: programmingblind@xxxxxxxxxxxxx
Subject: C program question
If I actually include the code, I think you can help me better. Sorry, I
didn't sleep last night.
#include <stdio.h>
/* function prototypes */
void initData(int *clockNumberPtr,float *wagePtr,float *hoursWorkedPtr);
void getHoursWorked(int entry,int * clockNumberPtr,float *hoursWorkedPtr);
float calculateOverTime(int entry, float *wagePtr,float *hoursWorkedPtr);
float calculateGrossPay(int entry, float *wagePtr,float *hoursWorkedPtr);
void displayEntry(int entry, int *clockNumberPtr,float *wagePtr,float
*hoursWorkedPtr);
struct emp
int main (char *argv, int argc)
{ /*get clock info*/
int clockNumber; /*employee number*/
float wage; /* declare wage */
float hoursWorked; /*enter hours worked*/
struct employee emp(5);
int i=0;//index for for loop
initData(clockNumber,wage,hoursWorked);
for (i=0;i<5;i++)
getHoursWorked(i,clockNumber,hoursWorked);
printf("Clock #\tWAge\thours\tOver time\tGross Pay\n");
for (i=0;i<5;i++)
displayEntry(i,clockNumber,wage,hoursWorked);
struct emp myempArray[5];
return(0);
} /*end get clock info*/
void initData(int *clockNumberPtr,float *wagePtr,float *hoursWorkedPtr)
{ /* declaring clock numbers and wage*/
int i; // index for for loop
emp[0].clockNumber=98401 ; /*first employee*/
emp[1].clockNumber=526488; /* second employee*/
emp[2]clockNumber=765349; /*third employee */
emp[3]clockNumber=34645; /*forth employee*/
emp[4]clockNumber=127615; /*fifth employee */
emp[0]wage=10.60; /* first employee wage
emp[1]wage=9.75; /*second employee wage
emp[2]wage=10.50; /* third employee wage */
emp[3]wage=12.25; /*employee 4 wage */
emp[4]wage=8.35; /* fifth employee wage 8/
// init hours worked to 0
for (i=0;i<5;i++)
hoursWorkedPtr[i]=0;
} /*end declaring clock and wage numbers*/
void getHoursWorked(struct employee emp[])
{ /*prompt for hours*/
printf ("Enter hours worked by %d: ",clockNumberPtr[entry]);
scanf_s("%f", &(hoursWorkedPtr[entry]));
} /*end prompt for hours*/
float calculateOverTime(int entry, float *wagePtr,float *hoursWorkedPtr)
{ /* figure out overtime */
float overTimeHours=hoursWorkedPtr[entry]-40;
float overTimePay=0;
if (overTimeHours>0)
overTimePay=overTimeHours*(wagePtr[entry]*1.5);
return (overTimePay);
} /* end figuring out overtime */
float calculateGrossPay(int entry, float *wagePtr,float *hoursWorkedPtr)
{ /* determine gross pay*/
float grossPay=0;
if (hoursWorkedPtr[entry]>40)
grossPay=(40*wagePtr[entry])+calculateOverTime(entry,wagePtr,hoursWorkedPtr)
;
else
grossPay=wagePtr[entry]*hoursWorkedPtr[entry];
return (grossPay);
} /*end determine gross pay */
void displayEntry(int entry, int *clockNumberPtr,float *wagePtr,float
*hoursWorkedPtr)
{ /*desplay results */
printf ("%d\t%0.2f\t%0.2f\t%0.2f\t%0.2f\n",
emp.clockNumber,
emp.wage,
emp.hoursWorked,
calculateOverTime(entry,wagePtr,hoursWorkedPtr),
calculateGrossPay(entry,wagePtr,hoursWorkedPtr));
} /* end desplay output*/
__________
View the list's information and change your settings at
http://www.freelists.org/list/programmingblind
__________
View the list's information and change your settings at
http://www.freelists.org/list/programmingblind
- Follow-Ups:
- Re: C program question
- From: John Miller
Other related posts:
- » C program question
- » RE: C program question
- » Re: C program question
- » RE: C program question
- » Re: C program question
- » RE: C program question
- » Re: C program question
- » RE: C program question
- » Re: C program question
- » RE: C program question
- Re: C program question
- From: John Miller