On Sun, Jan 24, 2010 at 5:22 PM, shamir shakir <[email protected]> wrote:
> HI,
> I'm being problemed with this one
>
> #include <stdio.h>
>
> #define D 6
>
> int main()
> {
> float array[D] ;
> float number ;
> float avarage ;
>
> number = 0 ;
> for(int i= 0 ; i<D; i++)
> {
> scanf("%d", &array[i]) ;
Wrong specifier:
scanf("%f", &array[i]);
> number == number + array[i] ;
== is comparison, = is assignment:
number = number + array[i] ;
And you should really be checking the result of the input:
if (scanf("%f", &array[i]) != 1){
printf("Error reading input\n");
}else{
number = number + array[i] ;
}
> }
>
> printf("Total : %f \n ", number ) ;
> avarage == number/D ; // results 0, why ?
== vs = again:
avarage = number/D ;
> printf("Average : %f ", avarage ) ; // occurs malresult, why ?
>
> return 0 ;
> }
>
> Still a newbie :)
> Thanks
--
PJH
http://shabbleland.myminicity.com/
http://www.chavgangs.com/register.php?referer=9375
http://www.kongregate.com/?referrer=Shabble