I need to implement some code into my program that changes the values of a 9 integer array, I tried using the following code but on my console screen it shows boxes and some random stuff, (so its not working for some reason.)
1 2 3 4
for (int iX = 0; iX <9; ++iX)
{
caBoard[iX] = (iX+1);
}
It could be that you are not creating the array correctly, I'm only assuming because you say you are getting random characters.
You might be doing this?
1 2
int size_of_array = 9;
caBoard[size_of_array];
If so either just put in 9 into caBoard right off the start OR make size_of_array constexpr.
My psychic powers predict that caBoard[] is an array of characters, not integers.
1 2 3 4 5 6 7 8
char caBoard[10] = {0}; // make length one more than required, to allow null terminator
for (char ix = '1'; ix <= '9'; ++ix)
{
caBoard[ix - '1'] = ix;
}
cout << caBoard << '\n';
or replace lines 3 to 6 with
1 2 3 4
for (int ix = 0; ix < 9; ++ix)
{
caBoard[ix] = ix + '1';
}