Hello again, another problem with this same exercise. I swear I am having so much trouble with arrays and functions >=(
Anyways, the exercise states to create 3 functions. One to receive golf scores(up to a maximum of 10 whilst enabling a user to end input early), one to display the golf scores, and one to return the average of those golf scores.
My compiler gives me an error @ line 9 and 10, I think they are both the same thing.
|9|error: invalid conversion from 'int*' to 'int'|
|9|error: initializing argument 1 of 'int scores(int, int)'|
|10|error: invalid conversion from 'int*' to 'int'|
|10|error: initializing argument 1 of 'void display(int, int)'|
||=== Build finished: 4 errors, 0 warnings ===|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <iostream>
using namespace std;
int scores(int, int);
void display(int, int);
int main()
{
int golfscores[10];
int numread = scores(golfscores, 10);
display(golfscores, numread);
return 0;
}
int scores(int myArr[], int max)
{
int value = 0;
for(int i = 0; i < max; i++)
{
cout << "Enter value #" << (i + 1) << ": ";
cin >> myArr[i];
if (!cin)
{
cin.clear();
while(cin.get() != '\n')
continue;
cout << "Bad input; input process terminated.\n";
break;
}
else if (!isdigit(myArr[i]))
cin.clear();
break;
value += 1;
}
return value;
}
void display(int myArr[], int max)
{
cout << "Golf scores : ";
for (int i = 0; i < max; i++)
{
cout << myArr[i] << " ";
}
}
|
Thank you for your time.