Need help with an Array in a class

the average.h (header file)

#ifndef H_average
#define H_average



class average
{
public:
void setFunctions (int n[100], int t);
int getNum () const;
int Sum () const;
int Ave () const;
int getTotal () const;
void print () const;
average ();
average (int n[100], int t);
int sum;
int ave;
private:
int num [100];
int total;

};

#endif



The average.cpp file


#include "average.h"
#include <iostream>
#include <string>

using namespace std;

const int ARRAY_SIZE = 100, i;
int n[ARRAY_SIZE] = {i};


void average::setFunctions (int n[100], int t)
{
if (n[100] >= 0)
n[100] = num[ARRAY_SIZE];
else
num[ARRAY_SIZE] = 0;
if (t >=0)
t= total;
else
total = 0;
}

int average::getNum () const
{
return num[ARRAY_SIZE];
}
int average::Sum () const
{
for (n[i] = 0; n[i]< 100; n[i]++)
{
int sum = 0;
sum = sum + n[i];

return sum;
}
}


and the main.cpp file

#include <iostream>
#include "average.h"


using namespace std;




int main()
{
average myAverage1;
int t;
int n[100];

cout << "how many numbers to you want to enter?" << endl;
cin >> t;
for (int i = 0;i<t;i++)
{
cout << "enter a number" << endl;
cin >> n[i];
}

myAverage1.getNum();
myAverage1.getTotal();
cout << "The sum of your numbers are is";
myAverage1.Sum();

cout << "Your average is:";
myAverage1.print ();

return 0;

}




My problem is initializing i!
You mean here:
1
2
3
4
5
6
7
8
9
10
int average::Sum () const
{
for (n[i] = 0; n[i]< 100; n[i]++)
{
int sum = 0;
sum = sum + n[i];

return sum;
}
}

?
Shouldn't it just look something like this:
1
2
3
4
5
6
7
8
9
int average::Sum () const
{
int sum = 0;
for(int i = 0; i < ARRAY_SIZE; ++i)
{
    sum += n[i];
}   
return sum;
}
Topic archived. No new replies allowed.