Stopping input

This is the code I am working on. We have to create a game known as Malom. As you can see from the code, you input a value into the board, which corresponds to a place on the board. The only problem we are having is that there are 24 places on the board, But the maximum amount of "stones" to be placed is 18 total(9 per player). We need to know how to stop to program from accepting input after 18 stones. Any response is appreciated thank you.

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
#include <iostream>
#include <Windows.h>
char gameboard (short);
int main()
{
	using namespace std;
	short boardn[24] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 
	short in;
	short playernum = 1;
	for( ; ; )
	{
		cout << gameboard(boardn[0]) << "----------" << gameboard(boardn[1]) << "----------" << gameboard(boardn[2]) << "    1  2  3" << endl;
		cout <<"|          |          |" << endl;
		cout <<"|          |          |" << endl;
		cout <<"|   "<< gameboard(boardn[3]) << "------" << gameboard(boardn[4]) << "------" << gameboard(boardn[5]) <<"   |" << "    4  5  6" << endl;
		cout <<"|   |      |      |   |" << endl;
		cout <<"|   |      |      |   |" << endl;
		cout <<"|" "   |    " << gameboard(boardn[6]) << "-" << gameboard(boardn[7]) << "-" << gameboard(boardn[8]) <<    "    |"   "   |" << "    7  8  9" << endl;
		cout <<"|   |    |   |    |   |" << endl;
		cout << gameboard(boardn[9]) << "---" << gameboard(boardn[10]) << "----" << gameboard(boardn[11]) << "   " << gameboard(boardn[12]) <<"----" << gameboard(boardn[13]) << "---" << gameboard(boardn[14]) << "    10 11 12    13 14 15" << endl;
		cout <<"|   |    |   |    |   |" << endl;
		cout <<"|" "   |    " << gameboard(boardn[15]) << "-" << gameboard(boardn[16]) << "-" << gameboard(boardn[17]) <<    "    |"   "   |" << "    16 17 18" << endl;
		cout <<"|   |      |      |   |" << endl;
		cout <<"|   |      |      |   |" << endl;	
		cout <<"|   "<< gameboard(boardn[18]) << "------" << gameboard(boardn[19]) << "------" << gameboard(boardn[20]) <<"   |" << "    19 20 21" << endl;
		cout <<"|          |          |" << endl;
		cout <<"|          |          |" << endl;
		cout << gameboard(boardn[21]) << "----------" << gameboard(boardn[22]) << "----------" << gameboard(boardn[23]) << "    22 23 24" << endl;
		cout << "The numbers to the right of the board correspond to the placement of a stone on the board."  << endl;
		cout << "Please select the placement of your stone. Player # " << playernum <<endl;
		cin >> in;
		boardn[in-1] = playernum;
		if (in > 24)
		{
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),4);
			cout << "Illegal move please re-enter a number that is between 1-24. \a" << endl;	
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
		}
		if (in < 0)
		{
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),4);
			cout << "Illegal move please re-enter a number that is between 1-24. \a" << endl;	
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
		}
		else
			playernum = playernum == 2 ? 1 : 2;
		
	}
}
char gameboard (short a)
{
	char b;
	switch(a)
	{
	case 0:
		b = 'X';
		break;
	case 1:
		b = '1';
		break;
	case 2:
		b = '2';
		break;
	};
	return b;
}
what about changing your for loop to loop only a certain number of times instead of forever?
change your for loop to (int i = 0; i<18; i++)
Hey jloundy, for some reason when I input the code you posted it gave me these two error codes:
error C2143: syntax error : missing ')' before ';'
and
error C2059: syntax error : ')'
post your loop
it should look exactly like this:

1
2
3
4
5
for(int i=0; i<19; i++)
{
// rest of code

}
Oh I took out the for by accident, it works now thank you
thats what i thought
Topic archived. No new replies allowed.