jeudi 23 février 2023

Generating random size of an array c++ [duplicate]

I made a class called Room and i need to generate an array with random size, but compiler says it needs a constant value. My code:

int randN(int from, int to) {
    return from + rand() % (to - from + 1);
}

void main() {
    srand(time(nullptr));
    
    int roomSize = randN(5, 13);
    const int rs = roomSize;
    Room raray[rs];

}

I tried to write:

const int roomSize(randN(5,13));

but it doesn't work.




Aucun commentaire:

Enregistrer un commentaire