Stuck on a for loop entry

I am trying to get this code eventually to read in a maze file to move the smiley face around in. But right now my current snag is the yes or no to enter the for loop.
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <iostream>
#include <windows.h>
#include <conio.h>
#include <time.h>
using namespace std;

int main()

{
    int name;
    char ans;
    cout<<"Please enter Player name:";
    cin>>name;
    cout<<"Are you ready to play?(y/n):";
    cin>>ans;

    if(ans=='y')
    {


        clock_t sTime, eTime;
        sTime=clock();
        system("pause");
        eTime=clock()-sTime;
         char boundary[25][25];
        int row, col;
        //initalizes array to spaces
        for (row=0; row<25; row++)
        {
            for (col=0; col<25; col++)
            {
                boundary[row][col]=' ';
            }
        }
        //makes top and bottom border
        for (col=0; col<25; col++)
        {
            boundary[0][col]=219;
            boundary[24][col]=219;
        }
        //makes left and right border

        for (row=0; row<25; row++)
        {
            boundary[row][0]=219;
            boundary[row][24]=219;
        }
        //places starting point of face

            row=23;
            col=1;
            boundary[row][col]=1;
            while(true)
            {
                if (GetAsyncKeyState(VK_UP) !=0 && boundary [row-1] [col] ==' ')
                {
                    boundary [row] [col] =' ';
                    row-- ;
                    boundary [row] [col] =1;
                }
                if (GetAsyncKeyState(VK_LEFT) !=0 && boundary [row] [col - 1] ==' ')
                {
                boundary [row] [col] =' ';
                col-- ;
                boundary [row] [col] =1;
                }
                    if (GetAsyncKeyState(VK_RIGHT) !=0 && boundary [row] [col + 1] ==' ')
                    {
                        boundary [row] [col] =' ';
                        col++ ;
                        boundary [row] [col] =1;
                    }
                        if (GetAsyncKeyState(VK_DOWN) !=0 && boundary [row + 1] [col] ==' ')
                        {
                            boundary [row] [col] =' ';
                            row++ ;
                            boundary [row] [col] =1;
                        }
            }

                    system("cls");

                    for (int r=0; r<25; r++)
                    {
                        for (int c=0; c<25; c++)
                        {
                            cout << boundary[r][c] ;
                        }
                        cout << endl ;
                    }



                getch();
                cout<<"Time elapsed equals "<<double(eTime)/double(CLOCKS_PER_SEC);
}


    else
    {
        return 0;
    }

Any help would be greatly appreciated.
Last edited on
When I press y it just shows press any key to continue... and freezes. I have to click the red x to be able to close the console window. Using ans=getch();
Last edited on
Have you tried stepping through it in a debugger to see what's going on? Or putting in any debugging output?
Have a look at line 23. I think this is some special Microsoft trick to confuse programers?
Topic archived. No new replies allowed.