Ok I have gotten my program to do almost what it is supposed to do. I am having a problem with averaging the numbers in the array. please can anyone explain why it is not averaging correctly. Here is my code so far.
Code:
#include<iostream>
using namespace std;
class Student
{
private:
int idnum;
double grades[5];
int totnumgrades;
public:
Student(int=0,double[5]=0,int=0);
int studentid();
double testgrade();
double average();
};
Student::Student(int stidnum,double grades[5],int totnumgrades) //constructor
{
}
int Student::studentid()
{
cout<<"Please enter your student id number\n"<<endl;
cin>>idnum;
return idnum;
}
double Student::testgrade()
{
int i;
cout<<"\nPlease enter a single test grade:\n "<<endl;
cin>>grades[1];
return grades[1];
}
double Student::average()
{
int i;
int sum=0;
int average=0;
cout<<"\nPlease enter four more grades to calculate your average"<<endl;
for(i=1;i<5;i++)
{
cin>>grades[i];
}
for (i=0;i<5;i++)
{
sum+=grades[i];
average = sum/5;
}
return average;
}
int main()
{
Student a;
Student b;
cout<<"\nThe student id number entered is:\n"<<a.studentid()<<endl;
cout<<"\nThe test grade you entered has been updated as: \n"<<b.testgrade()<<endl;
cout<<"\nThe average of the grades entered is\n"<<b.average()<<endl;
system("pause");
return 0;
}