Re: c programming functions questions

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

That's what I'm trying to do is put everything in it's own function. I'm just wondering if I need to start form scratch or if I should just work with what's there. I have a little of it done, I'll probably send in what I have later in the week to see if I'm on the right track or even close but so far I think I'm alright. ----- Original Message ----- From: "Littlefield, Tyler" <tyler@xxxxxxxxxxxxx>

To: <programmingblind@xxxxxxxxxxxxx>
Sent: Tuesday, October 16, 2007 5:52 PM
Subject: Re: c programming functions questions


I noticed daniel make a comment about the loop.
I don't think it matters... i++ takes i and adds 1. ++i adds 1 then assigns it to i, from what I know. You're not assigning it to a left-hand variable like: i=++x so it won't make a difference, the one loop will just add 1 to i.
Also, this is what works for me.
Put separate tasks in their own functions. Later on, when you have the function being called more and more, or it's being used in a large project, you only need to change that one class.
Enjoy,
Thanks,
Tyler Littlefield.
Vertigo head coder
"My programs don't have bugs, just randomly added features."
msn: tyler@xxxxxxxxxxxxx
email: tyler@xxxxxxxxxxxxx
aim: st8amnd2005
web: tysdomain.com
----- Original Message ----- From: "John Miller" <n1umj@xxxxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Tuesday, October 16, 2007 8:54 AM
Subject: c programming functions questions


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



--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 269.14.12/1072 - Release Date: 10/15/2007 5:55 PM


__________
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: