Snake Game

i'm trying to create a snake game and i have just created the frame and i wanna see if this will work or not some one guid me please

#include <iostream>
int print_border(int x,int length){
while (x<length){
std::cout<< "* ";
x++;
}
}
int print_border2 (int x, int y,int length){
while (y<length){
std::cout<< "\n* *";
y++;

}
if (y==length){
std::cout<< "\n";
print_border(x,length);
}
}
int main(){
int x=0;
int y=0;
int length=16;
bool game_start=true;
while (game_start == true){
print_border(x,length);
print_border2 (x, y,length);
}
return 0;
Line 7: print_border is type int and must return a value, or be declared type void.

Line 18: print_border2 is type int and must return a value, or be declared type void.

Line 24: You never set game_start to false, so this is just going to loop forever.

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

thanks for those tips
can you compile my code and see what's going on i want the square to loop in the same screen but the square goes down i don't know why can you help me with this..
I already tried to run it after fixing the errors on lines 7 and 18.
As I stated above, your program loops forever because of line 24.

Remove the loop and try to print the board once.

yeah i know that without the while loop it will print the square once but i want to keep refreshing the square so the game will be playable.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32


#include <iostream>
int print_border(int x,int length){
    while (x<length){
        std::cout<< "* ";
        x++;
    }
    return 0;
}
int print_border2 (int x, int y,int length){
    while (y<length){
        std::cout<< "\n*                             *";
        y++;

    }
    if (y==length){
            std::cout<< "\n";
            print_border(x,length);
        }
    return 0;
}
int main(){
    int x=0;
    int y=0;
    int length=16;
    bool game_start=false;

    print_border(x,length);
    print_border2 (x, y,length);
    return 0;
}


Your next step should be to get some input from the user.

Focus on getting the first turn working. Once the first turn is working, then you can implement your game loop.
Topic archived. No new replies allowed.