need help with a number game

This is a discussion on need help with a number game within the C++ Programming forums, part of the General Programming Boards category; Hello there
Im trying to make a numbers game and i have gotten so far as to display a 3*3 ...

need help with a number game

Hello there

Im trying to make a numbers game and i have gotten so far as to display a 3*3 grid, fil it with the numbers 1-8 and and X in the 9'th grid, and now what i need some help with is getting X to move around, your supposed to move X with W A S D as seen below. When X moves around the grid it's supposed to change position with the current number of the position it moves to, and it's this that i have problem with. Getting it to move, and getting it to switch position wich i hope someone could be very kind to help me with/solve? so far i managed to make it show it's current position on the grid.

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

Ok, lets say I hit "s" twice. What is y's value? Is it not 2? Ok, lets say I hit "s" twice more. Now what is my value? 4, right? I mean it told me that I cannot move there and what not. But my y is continuing to exist out of bounds.

Ok, lets say I hit "s" twice. What is y's value? Is it not 2? Ok, lets say I hit "s" twice more. Now what is my value? 4, right? I mean it told me that I cannot move there and what not. But my y is continuing to exist out of bounds.

Maybe inside the if statement you could set y = 2?

ah i se, thank you! now the thing i still cant figure out is moving X and how to swap positions with X and the numbers :/

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

thank you very very much for the guidence guys! i dont know how to thank you enough, i though have one last question if i may. :/

When the game starts you have the starting grid and the goal grid showing and under it this line appears "You move by using W A S D on you keyboard:" and you get to punch in someting. now, each time someting is enterd, a while loop goes on and shows "You move by using W A S D on you keyboard:" again and you get to punch in someting new. What i cant get working is that so each time you punch in someting and the loop goes on, the START grid is supposed to also reload also, ive been breaking it each time ive been trying to get the grid to loop also :/ what should i do?

Why not start off by changing your main() function to write the grids just using a loop or two, first of all. Perhaps it couldn't hurt to write a function that draws grides. I mean the code to draw a grid is fundamentally the same each time.