c programming functions questions

  • From: "John Miller" <n1umj@xxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Tue, 16 Oct 2007 10:54:25 -0400

Hi all, I guess this week we have to convert to functions all the work we've done. As it's explained to me, it looks pretty easy, as the examples the teacher uses as supposed help for the homework, it looks like I have to pretty much start over from scratch instead of just changing the program as I've done in the past 4 assignments. Can someone take a look at the below code and let me know if I would be better starting from scratch? any other helpful suggestions or help are welcome as well, I think though, it's just a case of dividing the program up pretty much in to smaller chunks of code, like the clock number still all goes together, and then hours, and so-on. Not sure about the output section at the bottom, but I have no intention to finish it until very late in the week anyway so I can worry about that then. *note, if anyone wants to use skype or any other chat info to explain this it will have to be tomorrow as I have a ton of work to get ready for a meeting tonight and where I didn't sleep much the last 5 nights, I'm only working on this for another 40 minutes or so and then after lunch, probably taking a nap before getting meeting stuff ready*

anyway, here's the code.

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 overtimepay;

float wage[5];

/* hourly wage */

int i;

/* Prompt for employee information */

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

{

printf("enter your employee number: ");

scanf_s("%d", &clock[i]);

printf("Enter the wage: ");

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

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

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

/*if statement for overtime*/

if ( hours[i] > 40 )

{ /*begin if*/

overtime = hours[i] - 40;

overtimepay = 1.5 * overtime;

gross[i] = wage[i] * hours[i] + overtimepay;

} /*end if*/

else

{ /*begin else*/

gross[i] = wage[i] * hours[i];

} /*end else*/

} /*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)

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

Other related posts: