do I use ';' then? lol
Printable View
do I use ';' then? lol
Ok I just did a sweep and fixed a lot of errors... I still have a few though :(
I have 5 errors left to go lol
thanks for helping me so far.. I would've probably just given up without help :/
Errors:
In function `int main()':
177 [Warning] division by zero in `(n / 2) % 0'
177 At global scope:
220 expected declaration before '}' token
With code:
Code:#include <iostream>
using namespace std;
int gameStatus(char gameboard[3][3])
{
// To check if player one has won
if (gameboard[0][0] == 'X' && gameboard[0][1] == 'X' && gameboard[0][2] == 'X' ||
gameboard[1][0] == 'X' && gameboard[1][1] == 'X' && gameboard[1][2] == 'X' ||
gameboard[2][0] == 'X' && gameboard[2][1] == 'X' && gameboard[2][2] == 'X' ||
gameboard[0][0] == 'X' && gameboard[1][0] == 'X' && gameboard[2][0] == 'X' ||
gameboard[0][1] == 'X' && gameboard[1][1] == 'X' && gameboard[2][1] == 'X' ||
gameboard[0][2] == 'X' && gameboard[1][2] == 'X' && gameboard[2][2] == 'X' ||
gameboard[0][0] == 'X' && gameboard[1][1] == 'X' && gameboard[2][2] == 'X' ||
gameboard[0][2] == 'X' && gameboard[1][1] == 'X' && gameboard[2][0] == 'X')
return 1;
// To check if player two has won
else if (gameboard[0][0] == 'O' && gameboard[0][1] == 'O' && gameboard[0][2] == 'O' ||
gameboard[1][0] == 'O' && gameboard[1][1] == 'O' && gameboard[1][2] == 'O' ||
gameboard[2][0] == 'O' && gameboard[2][1] == 'O' && gameboard[2][2] == 'O' ||
gameboard[0][0] == 'O' && gameboard[1][0] == 'O' && gameboard[2][0] == 'O' ||
gameboard[0][1] == 'O' && gameboard[1][1] == 'O' && gameboard[2][1] == 'O' ||
gameboard[0][2] == 'O' && gameboard[1][2] == 'O' && gameboard[2][2] == 'O' ||
gameboard[0][0] == 'O' && gameboard[1][1] == 'O' && gameboard[2][2] == 'O' ||
gameboard[0][2] == 'O' && gameboard[1][1] == 'O' && gameboard[2][0] == 'O')
return 2;
// To check for a tie
else if (gameboard[0][0] != ' ' && gameboard[0][1] != ' ' && gameboard[0][2] != ' ' &&
gameboard[1][0] != ' ' && gameboard[1][1] != ' ' && gameboard[1][2] != ' ' &&
gameboard[2][0] != ' ' && gameboard[2][1] != ' ' && gameboard[2][2] != ' ')
return 0;
// Otherwise continue..
else
return 3;
}
void displayBoard(char gameboard[3][3])
{
// Used to display the gameboard
cout << gameboard[0][0] << "|" << gameboard[0][1] << "|" << gameboard[0][2] << "---------";
cout << gameboard[1][0] << "|" << gameboard[1][1] << "|" << gameboard[1][2] << "---------";
cout << gameboard[2][0] << "|" << gameboard[2][1] << "|" << gameboard[2][2];
}
int main()
{
int x=0, y=0, n;
char name1[15], name2[15];
char gameboard[3][3] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '};
//Welcome and initialize everything
cout << "Welcome to this game of Tic Tac Toe" << "\n";
cout << "First player, enter your name:" << "\n";
cin >> name1;
cout << "Second player, enter your name:" << "\n";
cin >> name2;
cout << "__|__|__" << "\n" << "__|__|__" << "\n" << " | | " << "\n";
cout << "You make a move by entering first the row number and then the column number" << "\n";
//Start game
for (n = 0; n < 9; n++)
{
// This if statement is for player one's moves
if (n / 2 % 1)
{
cout << name1 << ", make your move: ";
cin >> x;
cin >> y;
while (gameboard[x - 1][y - 1] != ' ')
{
cout << "\n" << "Illegal move, make another move:";
cin >> x;
cin >> y;
}
gameboard[x][y] = 'X';
displayBoard(gameboard);
if (gameStatus(gameboard) == 1)
{
cout << name1 << " has won!";
exit(1);
}
else if (gameStatus(gameboard) == 2)
{
cout << name2 << " has won!";
exit(1);
}
else if (gameStatus(gameboard) == 0)
{
cout << "Game tied";
exit(1);
}
else
break;
}
//This if statement is for player two's moves
else if (n / 2 % 0)
{
cout << name2 << ", make your move: ";
cin >> x;
cin >> y;
while (gameboard[x - 1][y - 1] != ' ')
{
cout << "\n" << "Illegal move, make another move:";
cin >> x;
cin >> y;
}
gameboard[x][y] = 'O';
displayBoard(gameboard);
if (gameStatus(gameboard) == 1)
{
cout << name1 << " has won!";
exit(1);
}
else if (gameStatus(gameboard) == 2)
{
cout << name2 << " has won!";
exit(1);
}
else if (gameStatus(gameboard) == 0)
{
cout << "Game tied";
exit(1);
}
else
break;
}
else
break;
}
}
}
oh yea thanks.. ok I'll see what I can do... *goes to fix errors!*
only one error left:
220 expected declaration before '}' token
which is the last line btw
Oh I think I had an extra }
I deleted it :)
Count your open-curly-braces. Count your close-curly-braces. Note that they are not the same. Remove extras.
Also: I hope you also fixed n/2%1, which also doesn't mean anything (just like n/2%0 didn't mean anything).
I did
thanks :) :)