Reputation: 3
class FinalList {
Location List[20];
int MaxSize;
int Size;
public:
FinalList()
{
MaxSize = 20;
}
void RunIt();
void Show();
void Mean();
void Menu();
};
void FinalList::Mean()
{
int K;
double Total;
double Average;
for(K=0 ; K < Size ; K++)
Total += List[K].Value;
Average = Total / Size ;
cout << "Average: " << Average << endl;
}
void FinalList::Show()
{
int Count;
for(Count = 0; Count < Size ; Count++)
List[Count].Display();
cout << "Average: " << Average << endl;
}
I can calculate the average value from the array in Mean()
. But how can I later access this value in Show()
?
Upvotes: 0
Views: 112
Reputation: 406025
You can either store it in an instance variable (like you're doing with MaxSize
) or make Mean()
return the average value instead of just printing it out.
If you make Mean()
return the average, then you can call it in your Show()
function like this:
cout << "Average: " << Mean() << endl;
Upvotes: 4