#include <iostream>
usingnamespace std;
void fill_array ( int golfArray[], int size);
double compute_average ( int golfArray[], int size);
int main()
{
int scores[5];
fill_array (scores, 5);
cout << "The average is: " << compute_average(scores, 5) << endl;
return 0;
}
void fill_array ( int golfArray[], int size)
{
for (int i = 0; i < size; i++)
{
cout << "Enter score for golfer number " << i+1 << ": ";
cin >> golfArray[i];
}
}
double compute_average ( int golfArray[], int size)
{
double total=0;
for (int i = 0; i < size; i++)
total = total + golfArray[i];
return total/size;
}
Replace the function calls with the code of the functions and replace the function parameters with the actual arguments.
Why do you need to do this anyway?
#include <iostream>
usingnamespace std;
double compute_average ( int golfArray[], int size);
int main()
{
constint size = 5;
int scores[size];
// fill_array
for (int i = 0; i < size; i++)
{
cout << "Enter score for golfer number " << i+1 << ": ";
cin >> scores[i];
}
cout << "The average is: " << compute_average(scores, 5) << endl;
return 0;
}
double compute_average ( int golfArray[], int size)
{
double total=0;
for (int i = 0; i < size; i++)
total = total + golfArray[i];
return total/size;
}
at the top the double compute_average ( int golfArray[], int size); Is this the function prototype? If I want this program purely all arrays would I need that? If I am trying to write this program without functions, do I simply delete that line? I know the double is what its returning, the next is function name, then to arguments it passes through, however is it safe to delete this line of code?
And I'm not sure what this line of code does? compute_average(scores, 5)
And for the compute_average when writing it without a function, there are no cins right? Just a cout >> average ?
at the top the double compute_average ( int golfArray[], int size); Is this the function prototype? If I want this program purely all arrays would I need that? If I am trying to write this program without functions, do I simply delete that line?
You don't need this, you can delete it and the function itself.
And I'm not sure what this line of code does?
That line of code is calling the function compute_average. You want to remove that as well and replace it will something like.
1 2 3 4
double total = 0;
/* add all the elements from scores to total */
total / size;
cout << total << endl;
And for the compute_average when writing it without a function, there are no cins right? Just a cout >> average ?
cout << average etc. Use << for output. >> is for input.