View Single Post
Old 01-25-2014, 01:12 PM   #2
Kekeb
davai
FFR Veteran
 
Kekeb's Avatar
 
Join Date: Dec 2006
Age: 33
Posts: 2,765
Default Re: C++ Conway's Game of Life

You're treating your grid like it's an array of characters when it's boolean (true or false, not '*', ' ', or any other character).

I suspect your confusion might stem from this line of code,
Code:
cout << (grid[y][x] ? '*' : ' ');
which isn't checking to see if the character within the grid is '*' or ' '. The ? operator equates the previous condition and evaluates one of the following expressions depending on the result of the condition (in this case, returning '*' if the grid is true (1) at (y,x) or returning ' ' if the grid is false (0) at (y,x)) The character that's returned by the statement is then passed into cout.

Be careful about extending beyond the bounds of your arrays.

Last edited by Kekeb; 01-25-2014 at 01:29 PM.. Reason: dont know c++
Kekeb is offline   Reply With Quote