Re: more C programming help

  • From: "John Miller" <n1umj@xxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Tue, 25 Sep 2007 19:13:18 -0400

Trying to get data for 5 employees with this loop. Thanks. I think it's going as it should now. ----- Original Message ----- From: "Jackie McBride" <abletec@xxxxxxxxx>

To: <programmingblind@xxxxxxxxxxxxx>
Sent: Tuesday, September 25, 2007 1:37 PM
Subject: Re: more C programming help


John, 1 thing is you've got clock as an int but you've got print %f,
which means print a float-u need 2 change that to %d.

I think  I'd also use clock++ rather than ++clock.  Also, u don't have
any braces w/these for loops.  In other words, what's gonna happen is
that u get the loops 2 iterate but each time u do it you're
overwriting the value of the variables of the iteration b4.

I'm not really sure what this code is supposed to accomplish, e.g. I
can't figure out if you're trying to get data for 5 employees, for 1
employee, or what.

My advice is that u write some pseudocode b4 actually diving in2 the
programming.  For example, pseudocode for 1 employee for a 5-day work
week would llook something like this:
get employee number (u should only need it once)
get gross wage (unless it varies, which is unlikely, u should only
need that once, too)
start loop
for each day (1-5) {
get hours worked
multiply hours by wage
add it to wage total
}
end loop
print employee number earned wage total

So, if your code is trying 2 accomplish what I think it is, u really
only need 1 for loop.

Do your pseudocode prior 2 programming & I think you'll b able 2 get a
much better idea of how 2 proceed w/code writing.

On 9/25/07, Nimer Jaber <nimerjaber1@xxxxxxxxx> wrote:
John Miller wrote:
> Hi all,
> Now, I have to take last week's assignment and make it loop. I can get
> some of it to work with the for loop, but not all. I don't know if I'm
> missing something or what's going on here. Obviously I'm missing
> something, but I have no clue what. I've pasted the code in below.
> the first item does loop, but once I start putting the coding in for
> the rest of it, it comes up with errors, mostly seeming to be focused
> around the hours line. The class notes are absolutely horrible at
> explaining this so I pretty much have had to look at sites online and
> stuff to get as far as I did.
>
> (start code)
> #include <stdio.h>
>
> main ()
>
> {
>
> int clock;
>
> /* clock number */
>
> float gross;
>
> /* gross pay */
>
> float hours;
>
> /* hours worked */
>
> float wage;
>
> /* hourly wage */
>
> /* Prompt for input values from the screen */
>
> for ( clock = 1; clock <= 5; ++clock )
>
> printf("enter your employee number: ");
>
> scanf_s("%d", &clock);
>
> printf("employee number %d\n", clock);
>
> for ) hours = 1; hours <= 5; ++hours )
>
> printf("Enter number of hours worked: ");
>
> scanf_s("%f", &hours);
>
> for ( wage = 1; wage <= 5; ++wage )
>
> printf("Enter the wage: ");
>
> scanf_s("%f", &wage);
>
> /* calculate gross pay */
>
> gross = wage * hours;
>
> /* print out employee information to the screen */
>
>
> printf("This employee worked %f hours with a per-hour basis of %f.\n",
> hours, wage);
>
> printf(" gross pay is %f.\n", gross);
>
> }
>
> (end code)
>
>
>
> Every place I look tells me to do it a little different but I must be
> close. The clock number does actually work somewhat.
>
> 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
>
>
Try changing it so that it's clock ++ instead of ++ clock
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind




--
Jackie McBride
Check out my homepage at:
www.abletec.serverheaven.net
__________
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: