Answer the question
In order to leave comments, you need to log in
Why don't the values in the struct change?
I am writing the game "Sea Battle". When changing the value of ships.x or ships.y (from the structure), the value does not change (
Did I write the function correctly at all?
struct Ships {
int x = 1;
int y = 1;
};
void CheckPressedKey(char** area, char** area_buf, int row, int col)
{
struct Ships ships;
int key, counter = 1;
while (counter > 0)
{
key = _getch();
switch (key)
{
case 77: //Вправо - D
{
if (ships.x + ships.number_decks - 1 < 9) ships.x += 1;
cout << ships.x; //Тут выводит верно )
PrintShips(area, area_buf, row, col);
} break;
}
}
}
void PrintShips(char** area, char** area_buf, int row, int col) {
struct Ships ships;
cout << ships.x; //Тут выводит 1 все время (
}
Answer the question
In order to leave comments, you need to log in
void CheckPressedKey(char** area, char** area_buf, int row, int col) { struct Ships ships;
static struct Ships ships;
void CheckPressedKey(char** area, char** area_buf, int row, int col, struct Ships *ships)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question