I've got an assignment, shortly described, i've got to make an simple battle naval game. I thought it would be easy but i'm stuck. But right now i'm stuck. I've got one problem, i can't properly show my array, it does't align well. It would be great if you could help me
void show(char BATTLEFIELD[columns][rows])
{
std::string alfa[rows + 1] = { "A|", "B|", "C|", "D|", "E|", "F|", "G|", "H|", "I|", "J|" };
char num[11] = { ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
for (int i = 0; i < 11; i++)
{
std::cout << std::setw(width) << num[i];
}
std::cout << std::endl;
for (int z = 0; z < (columns*width); z++)
{
std::cout << "-";
}
std::cout << std::endl;
for (int i = 0; i < columns; i++)
{
for (int z = 0; z < rows; z++)
{
if (z == 0)
{
std::cout << alfa[i];
}
std::cout << std::setw(width) << veld[i][z];
}
std::cout << std::endl;
}
std::cout << std::endl;
}
I'll put two pictures with the expected and unexpected result.
Expected result:
Unexpected result: