I was trying to create a program to calculate the sum, average, maximum and minimum numbers in an array. My program worked for the sum and the average but failed in getting the maximum and minimum values in the array. Can somebody help me solve this please....
Here is my code:CODE
#include<iostream.h>
float computeAvg(float b[], int n)
{
float sum1=0;
int c;
for( c=0; c<n;c++)
{
sum1=sum1+b[c];
}
return (sum1/n);
}
//compute maximum value in the array
float computemax(float b[],int n)
{
float max;
max=b[n];
for(int c=0; c<n; c++)
{
if(max>b[c])
max=b[c];
}
return max;
}//end of function
//the main function
int main()
{
float mysum=0;
int a;
int d=1;
float myFunc;
cout<<"Enter number of students: ";
cin>>a;
float *mark;
mark=new float[a];
for (int m=0;m<a;m++ )
{
cout<<"Enter number "<<d++<<":";
cin>>mark[m];
mysum=mysum+mark[m];
}
float myMax=computemax(mark,a);
myFunc=computeAvg(mark,a);
cout<<"The sum is: "<<mysum<<"\n";
cout<<"The average is: "<<myFunc<<"\n";
cout<<"The highest mark is: "<<myMax;
delete []mark;
return 0;
}