First Array Help

closed account (48T7M4Gy)
http://www.cplusplus.com/forum/general/178970/
DONT POST COPIES OF POSTS
closed account (N7GEwA7f)
I went ahead and changed a few things but some help would be great!
#include <IOMANIP>
#include <IOSTREAM>
#include <FSTREAM>
#include <CMATH>
using namespace std;

const int MAXSIZE = 100;


int loadArray(ifstream& infile, double data[], int arrayLimit);
double findMax(double resist[], int numPts);
double findMin(double resist[], int numPts);
double calcMean(double resist[], int numPts);
double geomMean(double resist[], int numPts);
double rmsAvg(double resist[], int numPts);
double harmMean(double resist[], int numPts);
void sortValues(double resist[], int numPts);

int main()
{
double resist[MAXSIZE];//maxsize of the resist
int numPts = 0;//number of points
ifstream infile("HW9resist.txt");
if (!infile)
{
cout<<"Error: could not open file"<<endl;
infile.close();
return 1;
}

numPts = loadArray(infile,resist, MAXSIZE);

cout<<"The maximum value is"<<findMax(resist, numPts)<<endl;

cout<<"The minimum value is"<<findMin(resist, numPts)<<endl;

cout<<"The mean is"<<calcMean(resist, numPts)<<endl;

cout<<"The geometric mean is"<<geomMean(resist, numPts)<<endl;

cout<<"The rms average is"<<rmsAvg(resist, numPts)<<endl;

cout<<"The harmonic mean is"<<harmMean(resist, numPts)<<endl;

sortValues(resist, numPts);

cout<<"The sorted list of values is:"<<endl;

for(int i = 0; i < numPts; i++)
{
cout<<resist[i]<<endl;
}

infile.close();
return 0;
}


int loadArray(ifstream& infile, double data[], int arrayLimit)
{
int numPts = 0;
while(numPts < arrayLimit && infile>>data[numPts])
{
numPts++;
}

if(numPts >= arrayLimit)
{
cout<<"Maximum number of data values reached"<<endl;
}
else if(!infile.eof())
{
cout<<"Error reading file"<<endl;
}
else
{
cout<<"End of file found"<<endl;
}

return numPts;
}

double findMax(double resist[], int numPts)
{
int i = 0;
double value = resist[i];
double max = resist[i];
while(i < numPts)
{
if(value > max)
{
max = value;
value=resist[i];
}
i++;
}
return max;
}

double findMin(double resist[], int numPts)
{
int i=0;
double value = resist[i];
double min = resist[i];
while(i < numPts)
{
if(value < min)
{
min = value;
value = resist[i];
}
i++;
}
return min;
}

double calcMean(double resist[], int numPts)
{
int i = 0;
double geo = pow(resist[i],1./numPts);
i++;
while(i <= numPts)
{
geo*=pow(resist[i],1./numPts);
i++;
}
return geo;
}

double geomMean(double resist[], int numPts)
{
int i=0;
double sum = 0;
while(i <= numPts)
{
sum += resist[i]*resist[i];
i++;
}
return sum;
}

double rmsAvg(double resist[], int numPts)
{
int i=0;
double sum = 0;
while(i <= numPts)
{
sum += resist[i]*resist[i];
i++;
}
return sum;
}

double harmMean (double resist[], int numPts)
{
int i=0;
double sum = 0;
while(i <= numPts)
{
sum += 1./resist[i];
i++;
}
return sum;
}

void sortValues(double resist[], int numPts)
{
for(int i = 0; i < numPts; i++)
{
if(resist[i] > resist[i+1])
{
double numPts = resist[i+1];
resist[i+1] = resist[i];
resist[i] = numPts;
}
}
}
closed account (48T7M4Gy)
C'mon country95.

This is not a homework site, especially where you don't even have the sincerity to point out where you are having problems. You are wasting time and depriving real students from getting a fair go.
Agreed @Kemort
Topic archived. No new replies allowed.