Re: a little C programming help I hope

  • From: "John Miller" <n1umj@xxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 17 Oct 2007 20:55:01 -0400

I'm so lost I think it's not even funny. It looks like we're supposed to only be prompted for hours at this point, I don't know, I really don't know what I'm doing here. Looking at what he says in the class notes it looks like all we should be prompted for is hours and the other numbers are in the program. It looks kind of different from here too but I'd have more faith in this one than what's in the class notes 90% of the time. I thought I got this, apparently I don't. I don't really have time to work on it at all tonight unless I stay up all night which this class isn't worth. I'm just so confused now. I guess that's what I get for thinking I had it close. ----- Original Message ----- From: "Martin Slack" <m.g.slack@xxxxxxxxxxxx>

To: <programmingblind@xxxxxxxxxxxxx>
Sent: Wednesday, October 17, 2007 3:50 PM
Subject: Re: a little C programming help I hope


Hmmm,

There are a number of problems here John. Firstly, you have to declare a prototype for each function before the start of main. Then in main, you declare an instance of the function you want to use so you can call it. Finally, and it can be after the end of the main function, you need to define the actual body of the function.

So, just thinking about inputting the clock numbers, your program might look like:

#include <stdio.h>

/* function prototypes */
int getClockNumber (int n);
void printArray(int* array);

int main (void)
{
 int clock[5]; /* clock numbers */
 int i;

/* Prompt for clock numbers */
for (i = 0; i < 5; ++i)
{ /*begin for loop*/
 /* call getClockNumber to return one clock number
 clock[i] = getClockNumber (i);
} /* end of for loop */

/* check the information has reached the array */
printArray (clock);
return 0;
} /* end of main */

/* define functions */
int getClockNumber (int n)
{
 int value;

 printf("input clock number %d: ", n+1);
 scanf_s("%3d", &value);
 return value;
}


void printArray (int* array)
{
 int i;

 for(i = 0; i < 5; i++)
 {
   printf("\n%d", array[i]);
 }
}

Obviously you will need to write more functions to input the rest of the information and print out the results.

This approach still leaves a certain amount of looping structure in the main function, but I don't know whether your teacher wants you to put the looping in the "get" functions so that main is just a straight list of function calls.

 hth

Martin

----- Original Message ----- From: "John Miller" <n1umj@xxxxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Wednesday, October 17, 2007 3:52 PM
Subject: a little C programming help I hope


Hi hope this is just a little help this time. I've been working on this long enough this morning, and last night and before I finish and find out I screwed up royally, I'm wondering if some one can look this over and let me know how I've done so far, what I might want to do different and since I am getting stuck a little, maybe a little advice on how to do the rest of it though, if I am very close, or good here I think I know where I'm going with the rest of it. this is just what I get from the class notes and I'm getting to the point where I'm not comfortable with what I am doing though I'm about 90% sure I started off right.
Thanks,

(begin code)

#include <stdio.h>

int main (void)

{

int clock[5];

/* clock number */

float gross[5];

/* gross pay */

float hours[5];

/* hours worked */

float overtime;

float wage[5];

/* hourly wage */

int i;

/* Prompt for employee information */

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

{ /*begin for loop*/

#include float GetClockedHours ( unsigned long int ClockNumber )

{ /* begin clocked hours function */

float ClockedHours;

printf ( "Enter hours worked for clock %6lu: ", ClockNumber );

return ( clocked hours );

}


printf("Enter number of hours worked: ");

scanf_s("%f", &hours[i]);

void calc_gross_pay1 (float wage[], float hours[], float ot_pay[],

float gross_pay[], int emp_count)

{ int i; /* array index */

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

{

/* test to see any overtime was worked */

if (hours[i]> 40)

/* calculate gross pay */

gross_pay[i] = 40 * wage[i] + ot_pay[i];

else gross_pay[i] = wage[i] * hours[i];

}



GrosslyPaid[5]; /* gross pay array */ unsigned int NumberOfEntries = 5; /* number of entries */ float OvertimeHours[5]; /* overtime hrs array */ /* wage rates array */ float WageRate[5] = { 10.60, 9.75, 10.50, 12.25, 8.35 }; /* Prompt for input values from the screen */ /* calculate overtime hours and gross pay */ for ( EntryNumber = 0; EntryNumber < NumberOfEntries; EntryNumber++ ) { ClockedHours[EntryNumber] = GetClockedHours ( ClockNumber[EntryNumber] ); OvertimeHours[EntryNumber] = CalcOvertimeHours ( ClockedHours[EntryNumber] );

GrosslyPaid[EntryNumber] = CalcGrossPay ( ClockedHours[EntryNumber], OvertimeHours[EntryNumber], WageRate[EntryNumber] );

}

} /*end first for*/

/* calculate gross pay */

/* print out employee information to the screen */

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

{ /*start printf loop*/

printf ("\t----------------------------------------------------------\n");

printf ("\tClock#        Wage        Hours        Gross\n");

printf ("\t----------------------------------------------------------\n");

printf ("\t%06i %5.2f %5.1f %7.2f\n",clock[i],wage[i],hours[i],gross[i]); printf("This employee worked %f hours with a per-hour basis of %f.\n", hours[i], wage[i]);

printf(" gross pay is %f.\n", gross[i]);

} /* end printf loop*/


return 0;

}

(end code)







John Miller N1UMJ
AIM and yahoo messenger: N1UMJ Skype: n1umjjohn
home page:
http://home.comcast.net/~n1umj/wsb/html/view.cgi-home.html-.html
myspace: http://www.myspace.com/n1umj
__________
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: