Printing out values of array in another function

What am I doing wrong?

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
#include <iostream>
using namespace std;
int storeValues();
void print();

int main()
{
    print();
}    
    
    int storeValues()
    {
        int myArray[15];
        int returnArray;
        cout << "Please enter 15 values." << endl;
        for(int i=0; i<15; i++)
        {
            cin >> myArray[i];
            returnArray=myArray[i];
        }
        return returnArray;
    }
    
    void print()
    {
        int getValues=storeValues();
        for(int i=0; i<15; i++){
            cout << getValues << endl;
        }
    }
you're returning an int from storeValues, and not an int array.
How would I return an array, then use it in the void print() function?

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
#include <iostream>
using namespace std;
int storeValues();
void print();

int main()
{
    print();
    return 0;
}    
    
    int storeValues()
    {
        int myArray[15];
        int returnArray;
        cout << "Please enter 15 values." << endl;
        for(int i=0; i<15; i++)
        {
            cin >> myArray[i];            
        }
        return myArray[i];
    }
    
    void print()
    {
        int getValues=storeValues();
        for(int i=0; i<15; i++){
            cout << getValues << endl;
        }
    }
Topic archived. No new replies allowed.