Returning Array Values from Functions

I have a table of numbers created. For Table A the values contain the numbers
1-10. If the user were to enter 0, the function would return 1. If the user were to enter 9, the function would return 10. How would this be possible? Please help, thanks.

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
#include <iostream>
using namespace std;

int LArray[10];
int LArray2[10];

int lookupValueA () {
   
}

int lookupValueB () {

}

int main() {
    int LArray[10] = {1,2,3,4,5,6,7,8,9,10};

    int LArray2[10] = {0,0,0,0,0,0,0,0,0,0};
    cout << "A" << "\t" << "B" << endl;
        for (int i = 1; i <= 10; i++) {
            LArray2[i] =i*15;
            cout << i << "\t" << LArray2[i] << endl;
        }


    int num;
    cout << "\nEnter a number or -1 to Quit." << endl;
    cin >> num;
    while (num != -1) {
        cout << "The value in the array is " << endl;
    }

    return 0;
}
Last edited on
The lookup function should take an int as an argument, then use that number to return the appropriate value from the array.

Edit:

Try to avoid using global variables (Put hem in main instead)

Declare your functions before main, then put their definitions after main.
Last edited on
Topic archived. No new replies allowed.