I need help using rand / <ctime>

I'm creating a basic minesweeping
Last edited on
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
#include <iostream>
#include <cstdlib>
#include <ctime>

int main()
{
    const int SIZE = 5 ;
    const char MINE = 'M', NOT_MINE = 'O' ;

    std::srand( std::time(0) ) ;

    char guessarray [SIZE][SIZE] ;
    for( int row = 0 ; row < SIZE ; ++row )
        for( int col = 0 ; col < SIZE ; ++col )
            guessarray[row][col] = NOT_MINE ;


    int num_mines_to_be_placed = 10 ;
    while( num_mines_to_be_placed > 0 )
    {
        const int row = std::rand() % SIZE ;
        const int col = std::rand() % SIZE ;
        if( guessarray[row][col] != MINE )
        {
            guessarray[row][col] = MINE ;
            --num_mines_to_be_placed ;
        }
    }
}
Topic archived. No new replies allowed.