Multidimensional Array with rand()

This is part 2 of an earlier post.
I know how to create a 5x5 array. I am just having problems with part where they can occur one time.
I hope someone can help.

In this task, you will generate a 5×5 array and fill it with random integers between 0 and 24 inclusive and each number should occur exactly once.

Here is what I have so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  void MultiU (){
     int size = 5;
     int multiU[5][5];
    srand(time(0));
    for (int row = 0; row < size; row++){  //creates the 5x5 board
        for (int column = 0; column < size; column++){ 
           multiU[row][column] = rand() %25; 
        
        } 
    } 
    for (int row = 0; row < size; row++){  //thought this would check to see if the number occurred and if it did then it would assign it a new random number but it did not work
        for (int column = 0; column < size; column++){
            if (multiU[row][column]== multiU[row][column+1]){
                   multiU[row][column] = rand() %25;   
            }    
        }      
}   //where I would output the array
        for (int row = 0; row < size; row++){  
            for (int column = 0; column < size; column++){         
                cout << multiU [row][column]<< ' ';
        } 
        cout << endl;
    } 
}
Last edited on
Hey bs319 don't post multiple questions on exactly the same topic. It's extremely selfish!!
Registered users can post here. Sign in or register to post.