The program looks fine to me already. What's wrong with it?
make the functions call by address
I don't know what you mean by this.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
Right direction but lots of defects in OP code.
The OP title does not bear a relation to the real OP problems.
Think about:
// Never fix array size in a function!
int getLargest(const int* a, int n)
{
int largest = 0;
if (a && n > 0) {
int largest = a[0];
for (int i = 1; i < n; i++)
if (largest < a[i])
largest = a[i];
}
return largest;
}
// The same notes as above +
// integer division corrected.
double getAverage(const int* a, int n)
{
double avg = 0.0;
if (a && n > 0) {
for (int i = 0; i < n; i++)
avg += a[i];
avg = (double)avg/n;
}
return avg;
}
...
// Pass array size to the functions
double average = getAverage(a,9);
int lgst = getLargest(a,9);
// That's all, print these vars...
Yet another tip: instead of cumbersome
ifstream file1; // INPUT stream, why ios::in later?
...
file1.open("...",ios::in);
...
if (file1.is_open() == true) // why == true?
keep it simple:
ifstream file1("...");
// always test operator >> result:
for (i = 0; i < 9 && (file1 >> a[i]); i++)
{}
if (i < 9) { // open failed or bad input
...
}
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348