Need help in C++ 2D Arrays

Hello its my first time using arrays and im stuck in this How can i change the values inside a 2D array and print it out for example i want to replace the 1s with " " (space) and the 2s with the "*" Sign and then print them out

how can i do that?

this is my code:
------------------------
#include <iostream>

using namespace std;

int main(){

int Xshape[5][5] = {{2,1,1,1,2},
{1,2,1,2,1},
{1,1,2,1,1},
{1,2,1,2,1},
{2,1,1,1,2},

};
{
for (int row = 0; row<5 ; row++)
for (int column=0; column < 5; column++)
{
cout << Xshape[row][column] << endl;
}

}
system("pause");

}
-----------------------------------------------------
can someone help me please?
You have an array of integers. There is no integer with the value " " (space) and there is no integer with the value "*". " " and "*" are characters. Perhaps you meant to make an array of char.

Assuming you did mean to do that,

1
2
3
4
5
6
7
8
9
for (int row = 0; row<5 ; row++)
for (int column=0; column < 5; column++)
{
if Xshape[row][column]=='1'
{ Xshape[row][column] = " ";}
if Xshape[row][column]=='2'
{ Xshape[row][column] = "*";}
cout << Xshape[row][column] << endl;
}
Last edited on
Topic archived. No new replies allowed.