Having trouble assigning return value to a variable?

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.
Try this:

1
2
3

    int numread = scores( &golfscores[ 0 ], 10 );
closed account (DSLq5Di1)
1
2
3
4
5
int scores(int, int);
void display(int, int);

int scores(int myArr[], int max) { .. }
void display(int myArr[], int max) { .. }
Kooth, that removes two errors but leaves two.

@Sloppy9 thank you very much!
What are the errors now?
I didn't copy & paste them because simply applying the myArr[] to the prototypes caused the program to run properly. I noticed you are the same person who helped me yesterday, I am almost done this exercise and it feels great. Thanks for all your support (:
Yeah sloppy9 caught that one and I was looking right at it! I'm getting too old for this! :)


Glad I could help!
Here is the exercise from start to finish, with much help from Cplusplus.com (:

If any beginners out there like myself are reading this, I purchased the book c++ primer plus by stephen prata. He is releasing version 6 november 1st I believe(maybe it was september 1st?)

Excellent book, very thorough and I am very comfortable with what i've learned so far. (this is my first experience with any programming, I still don't know HTML or javascript :P)

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
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <cctype>

using namespace std;
int scores(int myArr[], int);
void display(int myArr[], int);
double average(int myArr[], int);
int main()
{
    int golfscores[10];
    int numread = scores(golfscores, 10);
    display(golfscores, numread);
    average(golfscores, numread);
    return 0;
}

int scores(int myArr[], int max)
{
    int q = 0;
    cout << "Please enter 10 values (non-numeric input to quit) : ";
       do
            {
                (cin >> myArr[q]).get();
                if(cin.fail())
                    {
                        break;
                    }
                else
                ++q;
            } while (q < 10 );
    return q;
}

void display(int myArr[], int max)
{
    cout << "Golf scores : ";
    for (int i = 0; i < max; i++)
    {
        cout << myArr[i] << " ";
    }
}

double average(int myArr[], int x)
{
    double total = 0;
    double average;
    for (int i = 0; i < x; i++)
        total = total + myArr[i];
    average = total/x;
    cout << "\nThe average is : " << average << endl;
    return 1;
}

Topic archived. No new replies allowed.