#include<iostream>
usingnamespace std;
constint ROWS = 5;
constint COLS = 5;
enum SYMBOLS {AT = '@', STAR = '*', X = 'X', ZERO = 0, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE};
void putStar(int initialSymbol[ROWS][COLS], int size); // I don't know if I need size.
int main()
{
SYMBOLS symbolArr[ROWS][COLS];
putStar(symbolArr); // How Do I call it
return 0;
}
void putStar(int initialSymbol[ROWS][COLS], int size)
{
//creating the rows for board
for (int i = 0; i < ROWS; i++)
{
//creating the column for the rows.
for (int j = 0; j < COLS; j++)
{
//Assign Enum '*' to The Board. How Do I do that?
}
}
//Parameter are the two dimensional array and size
return;
}
What I am trying to do is call the STAR function as an enum and fill a five by five.
To be more specific I am trying to:
"You will initialize the board using a function, passing in the two-dimensional array and
the size. This function will simply initialize each position on the board to the enumerated
type representing the initial value, which is the character ‘*’."
so it should look like this.
*****
*****
*****
*****
*****
PS: does the preview button work for anyone here? It never seems to work for me.
//creating the column for the rows.
for (int j = 0; j < COLS; j++)
{
//Assign Enum '*' to The Board. How Do I do that?
initialSymbol[i][j] = STAR;
however because your array isn't explicitly type char you will probably get an array full of (int)('*') values, that is, the ascii integer value of '*'. I would advise making the array of type char, or you can cast it carefully when you go to print it.
#include<iostream>
constint ROWS = 5;
constint COLS = 5;
// ZERO = '0': probably a good idea not to mix characters and integers
enum symbol : char { AT = '@', STAR = '*', X = 'X', ZERO = '0', ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE};
// 'array_type' is a succinct name (an alias) for 'two-dimensional array of ROWSxCOLS symbols'
using array_type = symbol[ROWS][COLS] ;
void fill( array_type& symbolArr, symbol sym ) // fill the array with symbol 'sym'
{
for( auto& row : symbolArr ) // for each row in the array
for( symbol& s : row ) s = sym ; // assign 'sym' to each symbol in the row
}
void putStar( array_type& symbolArr ) { fill( symbolArr, STAR ) ; }
void print( const array_type& symbolArr )
{
for( constauto& row : symbolArr ) // for each row in the array
{
for( symbol s : row ) std::cout << char(s) ; // print each symbol in the row as a character
std::cout << '\n' ; // and then, a new line
}
}
int main()
{
symbol symbolArr[ROWS][COLS] ;
putStar(symbolArr);
print(symbolArr) ;
std::cout << '\n' ;
fill( symbolArr, SEVEN ) ;
print(symbolArr) ;
}