Grid

I've been messing around with this for a couple of days now. I'm trying to generate a grid of 0s and move a 1 around with the numpad. the grid generates just fine, but i cant figure out how to make the 1 move correctly.

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

#include <iostream>
#include <string>
using namespace std;



	int arpos =0;
	int posx=2;
	int posy=3;
	int grid [10][10], row, col;
	string endD= "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";

void Array()//sets all initial values for array to 0;
{
	int grid [10][10], row, col;
	for (col = 1; col <10;col++)
	{
	for (row =1; row < 10; row++)
	{
		grid[row][col]=0;
		
	}
	}
}//end Array

int main()
{
	int exit=1;
	int input;

	while (exit !=0)//OVERLOOP
	{
		cout << endD;
	for (col = 0; col <10;col++)//columns
	{
		for (row =0; row < 10; row++)//rows
		{
			
			grid[row][col]=0;
			grid[posx][posy]=1;
			cout<< grid[row][col];
		
		}
	cout<<endl;
	}//end GRID
	cout << endl<<endl<<endl<<"MOVE\n";
	cin >> input;
	if (input == 0)//exit
	{
		exit = 0;
	}
	else if(input == 8, posy!=0)
	{
		posy--;
	}
	else if(input == 4, posx!=0)
	{
		posx--;
	}
	else if (input == 6, posx!=10)
	{
		posx++;
	}
	else if (input == 2, posy!=10)
	{
		posy++;
	}
	else
	{
		cout <<"INPUT NOT RECOGNIZED";
	}
	
	cout<<"Press Enter to continue";
	cin.get();
	cin.get();
	}//end OVERLOOP
	return 0;
}//end MAIN





You want AND && not a comma in your "if...else..." checks.
Topic archived. No new replies allowed.