www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/24/02:40:38

Message-ID: <383B780D.B36C890D@snetch.cpg.com.au>
Date: Wed, 24 Nov 1999 16:30:53 +1100
From: Michael Abbott aka frEk <20014670 AT snetch DOT cpg DOT com DOT au>
Organization: Student of Computer Power Institute
X-Mailer: Mozilla 4.05 [en] (Win95; I)
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: Please help me to find out the problem.
References: <81eabb$n6o$1 AT imsp026 DOT netvigator DOT com>
Reply-To: djgpp AT delorie DOT com

First of all I notice that none of the variables used are ever initialised
(specifically total)... What I would do is try and use the -wAll switch to
switch on all the warnings and see what that comes up with... A lot of those
warnings will actually be bugs in your program...

Otherwise I can't see a problem with it... If worse comes to worse, run a
debugger (Rhide would be the best bet) and step thru the program line by line
watching the variables to see what happens...

Also, why did you open a block inside the block? You could just as easily have
all the code inside the loop inside the one block.

You were asking about using a for loop only... You could take [pay] out and
replace the total with total += hr * rate tho' it's not strictly necessary :-)

Have fun,
Michael

Jason Yip wrote:

> The output of this program is always incorrect. Can anyone tells me why and
> correct it?? Thanks a lot!!
> What's more, I would like to make the prog to reject -ve input and shows a
> msg, then input again. How can I do?
> (Can I use for loop only?)
>
> #include <stdio.h>
> main ()
> {
> int i, ppl; float rate, hr, total, pay;
>  printf("Please input how many employees have overtime works: ");
>  scanf("%d",&ppl);
>  for(i=1;i<=ppl;i++){
>  {
>  printf("Please input the overtime hour of the no %d employee: ", i);
>  scanf("%f",&hr);
>  printf("Please input the overtime hourly rate of the no %d employee: ", i);
>  scanf("%f",&rate);
>  pay=hr*rate;
>  }
>  total+=pay;
>  }
>  printf("The total overtime pay is %.2f",total);
>  return 0;
> }



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019