--- In [email protected], "aammrr46" <[EMAIL PROTECTED]> wrote:
>
> what is wrong with that code
> it is not working
> it is simple but it ..............
> it take 10 numbers get max and min value and sum ang average
> but>>>>>
First it takes 3 (in words: THREE) numbers, not 10 (in words: TEN).
> #include <iostream.h>
> #include <math.h>
> void main()
Second no modern compiler should accept this prototype for main().
Please upgrade to a more recent compiler as soon as possible; then the
error shown below might already have been discovered by the compiler
itself.
> {int i;
> float a[3],s,e,ma,mi,z;
> char d;
>
> s=0.0;
> e=0.0;
> mi=0;
> ma=0;
> cout<<"plz enter the student degrres";
> for(i=0;i<3;i++)
> {cout<<"no ";
> cout<< i+1;
> cout<< " \n";
> cin>> z;
> a[i]=z;
> s=s+a[i];
>
> if(i=0){ma=a[i];
> mi=a[i];
> cout<<" f";}endl;
What about "if (i == 0)..." ? That should do the trick.
And what does the "endl;" mean?
> if (a[i]>=ma)ma=a[i];
> if (mi>=a[i])mi=a[i];
Change the checks to "if (a[i] > ma)..." and "if (mi > a[i])...". In
this application, this change won't do any particular good, but it's
better to learn correctly right from the start, and this means: logic
tells you that the minimum of n values is the SMALLEST of those
values; so checking for a new minimum requires you to check whether
the current value is LESS than the current minimum and only in this
case assign a[i] to the minimum.
Such nasty little issues can render your whole application wrong if
you are not cautious enough (see above, "if (i==0)...").
> }
> e=s/3;
> cout<< s;
> cout<< e;
> cout<< mi;
> cout<< ma;
> cin>> d;
> };
>
> plz send me fast
> thanx....
Is this fast enough?
And BTW some of my remarks from an earlier post today apply here as well:
1) Insert meaningful(!) comments into your source code. Always.
2) Choose meaningful names for variables.
3) Always introduce your own debugging output with some descriptive text.
Regards,
Nico