Return array from function!

Hi, I am trying to create a function that returns 5 random dice values back to main.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  
void generateDice (int *dice[5])
{
    string reRoll;

    for(int i = 0; i < 5; i++)
    {
        *dice[i] = 1+(rand()%6);
        cout << *dice[i];
    }
    cout << endl;
    cout << "What re-rolls? ";
    cin >> reRoll;

    for(int i = 0; i < reRoll.length(); i++) // re-roll
    {
        
        if(reRoll[i] == 'R' || reRoll[i] == 'r')
        {
            *dice[i] = 1+(rand()%6);
        }
    }
}


The code works on its own, but I can't seem to implement it to main, (I don't know a lot about pointers or return by reference hence all the '*'s.

Thanks.
The array parameter is a reference:
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
#include <iostream>

void foo( int arr[], int N ) {
  for ( int i = 0;  i < N; ++i ) {
    arr[i] = 2*i;
  }
}

int main() {
  int array[5] {};
  // before
  for ( auto x : array ) {
    std::cout << x << ' ';
  }
  std::cout << '\n';

  foo( array, 5 );

  // after
  for ( auto x : array ) {
    std::cout << x << ' ';
  }
  std::cout << '\n';

  return 0;
}
Last edited on
You're going to have to supply more information.

Since you say this function works on its own, then presumably the problem is not with the code you posted. How about posting the code you're having a problem with and an explanation of the problem you're having?


Topic archived. No new replies allowed.