Create board using seed values and functions (C++)

  arrays, c++, function, loops, matrix

Before you read ahead or try to help, this question is regarding my homework so the requirements to this question will be very specific.

I am writing a code that has 2 functions. The first function creates or initializes a 5*5 matrix for an array with numbers from 1 – 25 in random positions. The second function prints it. However, I am required to use a seed value of 233 in the srand() function which I am unsure of how to use despite constantly searching for it online. Anyways the printout should look something like this:

--------------------------
|  4 |  5 | 10 | 21 | 22 |
--------------------------
|  1|  11 | 3  | 19 | 20 |
--------------------------
| 24 |  18 | 16 | 14 |  9|
--------------------------
| 17 |  7  | 23 | 15 |  6|
--------------------------
|  2 | 12 | 13 | 25 | 8  |
--------------------------

The first and most easily explainable issue that I have is that all my display function is doing is printing all the values in a straight line and not in the format that I want it to be. the other part is that when I put 233 into srand(time(233)), it gives me an error and I’m not sure why even though it is required for my assignment. The second issue is that some of the numbers start reoccurring in the matrix and they are not supposed to, is there a way to make sure there are no duplicates in the matrix?

Although this is in the C++ language, what I have learned is the C style syntax (no std:: kinds of code or stuff like that because I haven’t learned it yet and I will not understand it) So far I have learned basic arrays, loops, and functions.

#include <iostream>
#include <ctime>

using namespace std;


const int ROW_SIZE = 5;
const int COLUMN_SIZE = 5;

void createBoard(int matrix[][5]);
void display(int matrix[][5]);

int main(){

    srand(time(233)); //the seed value error

    int matrix [5][5];

    createBoard(matrix);
    
    display(matrix);

}

void createBoard(int matrix[][5]){
    for (int i = 0; i < ROW_SIZE; i++){
        for(int j = 0; j < COLUMN_SIZE; j++){
            matrix[i][j] =  1 + rand() % 25;
        }
    }
}

void display(int matrix[][5]){

    cout<<"--------------------------"<< endl;
    for(int i = 0; i < ROW_SIZE; i++){
        for(int j = 0; j < COLUMN_SIZE; j++){
            cout<<"| "<< matrix[i][j];
        } 
    }
    cout<<"--------------------------"<< endl;
}

Source: Windows Questions C++

LEAVE A COMMENT