### Min,max and average of array Hi, I tried to make a program that print out a min , max and average value

but the average value doesn't work !!!

What should I do to fix this problem.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364`` ``````#include using namespace std; int main () { int array ,max=0,low=0,mid=0; for (int w=0 ; w<5; w++) { cout << "Enter value "<> array[w]; } max=array; low=array; mid=array; for (int i=0 ; i<5; i++) { if ( maxarray[i]) { low=array[i]; } else if (mid<=array[i]&&mid>=array[i]) { mid= max+low/2; } } cout << "the minimum value "<<" "<< low<< " " << "the average value "<
Last edited on Average is calculated like so:
 ``12345`` ``````int average=0; for(int i=0; i<5; i++) { average+=A[i]; } average/=5;`````` What kind of average are you trying to calculate?
http://en.wikipedia.org/wiki/Average

This `else if (mid<=array[i]&&mid>=array[i])` is only true if `mid == array[i]`. I don't think this is what you wanted. still doesn't work

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061`` ``````#include using namespace std; int main () { int array ,max=0,low=0,mid=0; for (int w=0 ; w<5; w++) { cout << "Enter value "<> array[w]; } max=array; low=array; mid=array; for (int i=0 ; i<5; i++) { if ( maxarray[i]) { low=array[i]; } mid+=array[i]; } mid/=5; cout << "the minimum value "<<" "<< low<< " " << "the average value "<

if the input were 1 ,2 ,5,8 and 6 the ave value will be 4

----

I want the average value of the input numbers ( the middle number ^^ )

like

1

11

5

10

100

the middle number will be 10 !

that what I want .
Last edited on closed account (28poGNh0)
You can do it at this way

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647`` ``````# include # include // To define INT_MAX : the highest nbr int takes using namespace std; int main () { int array ,maxNbr=0,minNbr=INT_MAX,sumNbr=0,tmpNbr; float aveNbr=0; for (int w=0 ; w<5; w++) { cout << "Enter value -> " ; cin >> array[w]; } for (int i=0 ; i<5; i++) { maxNbr = max(maxNbr,array[i]); minNbr = min(minNbr,array[i]); sumNbr += array[i]; } aveNbr = (float(sumNbr)/5); for(int i=0;i<4;i++) { for(int j=i;j<5;j++) if(array[i]>array[j]) { tmpNbr = array[i]; array[i] = array[j]; array[j] = tmpNbr; } } for(int i=0;i<5;i++) cout << array[i] << endl; cout << endl; midNbr = sumNbr/5;//midNbr = sumNbr/strlen(array); cout << "The minimum value is : " << minNbr << endl; cout << "The maximum value is : " << maxNbr << endl; cout << "The average is : " << aveNbr << endl; cout << "The middle number is : " << array << endl; return 0; }``````
Topic archived. No new replies allowed.