Hi, i am making a simple snake game but i cant seem to be getting it right. firstly, i want the game to terminate when it hits the wall, second once the snake hits the target it should randomly appear in another place inside the box. Please help me.
To make the starting position random, you could look into randomly generating a number to place a character within an array, This can be done using C-style random generation as you have used here or you can look into C++11's <random> header and generate a random number within a certain range.
Once you have generated that random number, you can insert a snake character (whatever you are using, it is not very clear from your code) at that position and mark that position as the head for your snake.
For wall detection, it is simple. Just check whether the next character in the array where the snake is supposed to move is a wall character. If it is, you can have a return value for your Layout function (I assume this function is generating every "frame" of your game) that specifies whether the player has hit a wall, and then you can use this return value to break out of the while loop in main() and terminate the program.
Also, for future reference, you should ask specific questions regarding parts of your code. This is helpful for you and for people reading your code. Nobody is going to have time to sift through hundreds of lines of unformatted and uncommented code to figure out what it does.