1234567891011121314151617181920212223242526272829
#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 ; } } }