Re: C program question

  • From: "John Miller" <n1umj@xxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Sun, 28 Oct 2007 08:25:36 -0400

Thanks. I had to submit it as it was, but hopefully the grade won't be too bad and I can fix it in time to work on next week's assignment, pointers I think it is. I guess that's just a case of adding something easy to this program when it's right so hopefully it won't be too bad and then there's only 1 more and the final to go. Unless I did worse on the midterm than I think, then I probably won't bother since I haven't had a decent night's sleep since the semester started and I think this class is why.


Other personal issues too, but I think this is number 1 reason.
Thanks, I'll definitely work on it with this info and see where I end up.
----- Original Message ----- From: "Ken Perry" <whistler@xxxxxxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Sunday, October 28, 2007 12:20 AM
Subject: RE: C program question


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
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: