Ibrahim El-Rayes
Ibrahim El-Rayes

Reputation: 17

How can I properly display this enumeration type?

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

const int Rows = 5;
const int Cols = 5;

Is this the proper way of declaring enums and using them?

enum Minesweeper { Mine = '@', Blank = '*', Loss = 'X'};

void StudentInfo ( );
void Information ( );
void make_board (Minesweeper Board [][Cols], int Rows, int mines);

int main ( )
{
        StudentInfo ( );

        Minesweeper Board [Rows][Cols];
        int mines = 0;

        cout << "       Enter amount of mines (5 - 10): ";
        cin  >> mines;

        Information ( );

        make_board (Board, Rows, mines);


        return 0;
}

How can I make this function out put the initialized character rather than outputting an integer?

 void make_board (Minesweeper Board [][Cols], int Rows, int mines)
        {
            for (int i = 0; i < Rows; i++)
                {
                        for (int j = 0; j < Cols; j++)
                        {
                                Board [i][j] = Blank;   // outputs the integer 42
                                cout << Board [i][j] << ' ';

                        }
                cout << endl;
                }

                return;
        }

This is the output that I am currently getting

42 42 42 42 42
42 42 42 42 42
42 42 42 42 42
42 42 42 42 42
42 42 42 42 42

Any help would be greatly appreciated. Thank you

Upvotes: 0

Views: 185

Answers (1)

Kerrek SB
Kerrek SB

Reputation: 477338

Try this:

cout << static_cast<char>(Board [i][j]) << ' ';

Upvotes: 1

Related Questions