Reputation: 1
I can't figure out what it wants from me at the end. This Tic-tac-toe is killing me. The error is in the last 4 "}" according to code blocks:
// Author: Aaron Yi
// Date: 17 October 2016
// Contact: [email protected] /347-570-5723
// MAC 125-3005 / Lab 03
#
include < iostream >
using namespace std;
int main() {
int Option;
char s1('1');
char s2('2');
char s3('3');
char s4('4');
char s5('5');
char s6('6');
char s7('7');
char s8('8');
char s9('9');
int PlayerTurn(1);
bool GameOverDecider(true);
cout << "\tActivating T^3" << endl;
cout << endl << endl;
cout << "\t(1)Begin!" << endl;
cout << "\t(2)Quit" << endl;
cout << endl;
cout << "Choose 1 or 2:";
cin >> Option;
if (Option == 1) {
do {
int PlayerTurn(1);
bool GameOverDecider(true);
cout << " " << s1 << " | " << s2 << " | " << s3 << endl;
cout << " -----+-----+-----" << endl;
cout << " " << s4 << " | " << s5 << " | " << s6 << endl;
cout << " -----+-----+-----" << endl;
cout << " " << s7 << " | " << s8 << " | " << s9 << endl;
cout << " -----+-----+-----" << endl;
char PlayerMarker;
if (PlayerTurn = 1) {
PlayerMarker = 'X';
} else {
PlayerMarker = 'O';
}
bool ValidTurn;
do {
char CurrentMove;
cout << "Player" << PlayerTurn << "'s turn, set move on what square: " << endl;
cin >> CurrentMove;
ValidTurn = true;
if (CurrentMove == '1' && s1 == '1') {
s1 = PlayerMarker;
} else if (CurrentMove == '2' && s1 == '2') {
s2 = PlayerMarker;
} else if (CurrentMove == '3' && s1 == '3') {
s3 = PlayerMarker;
} else if (CurrentMove == '4' && s1 == '4') {
s4 = PlayerMarker;
} else if (CurrentMove == '5' && s1 == '5') {
s5 = PlayerMarker;
} else if (CurrentMove == '6' && s1 == '6') {
s6 = PlayerMarker;
} else if (CurrentMove == '7' && s1 == '7') {
s7 = PlayerMarker;
} else if (CurrentMove == '8' && s1 == '8') {
s8 = PlayerMarker;
} else if (CurrentMove == '9' && s1 == '9') {
s9 = PlayerMarker;
} else {
cout << "Invalid Move, make another one:" << endl;
ValidTurn = false;
}
} while (!ValidTurn);
GameOverDecider = false;
bool WinGame = true;
if (s1 != '1') {
if (s2 == s1 && s3 == s1) {
GameOverDecider = true;
}
if (s4 == s1 && s7 == s1) {
GameOverDecider = true;
}
}
if (s1 != '9') {
if (s3 == s9 && s6 == s9) {
GameOverDecider = true;
}
if (s7 == s9 && s8 == s9) {
GameOverDecider = true;
}
}
if (s1 != '5') {
if (s1 == s5 && s9 == s5) {
GameOverDecider = true;
}
if (s2 == s5 && s8 == s5) {
GameOverDecider = true;
}
if (s4 == s5 && s6 == s5) {
GameOverDecider = true;
}
if (s3 == s5 && s7 == s5) {
GameOverDecider = true;
}
}
if (s1 != '1' &&
s2 != '2' &&
s3 != '3' &&
s4 != '4' &&
s5 != '5' &&
s6 != '6' &&
s7 != '7' &&
s8 != '8' &&
s9 != '9' &&
!GameOverDecider) {
GameOverDecider = true;
WinGame = false;
if (GameOverDecider) {
if (WinGame)
{
cout << "Player " << PlayerTurn << " totally wins!" << endl;
}
cout << " " << s1 << " | " << s2 << " | " << s3 << endl;
cout << " -----+-----+-----" << endl;
cout << " " << s4 << " | " << s5 << " | " << s6 << endl;
cout << " -----+-----+-----" << endl;
cout << " " << s7 << " | " << s8 << " | " << s9 << endl;
cout << " -----+-----+-----" << endl;
cout << "\tGame Over!" << endl;
cout << "\tAgain?(Y/N)?: ";
char PlayAgain;
cin >> PlayAgain;
if (PlayAgain = 'y') {
GameOverDecider = false;
s1 = '1';
s2 = '2';
s3 = '3';
s4 = '4';
s5 = '5';
s6 = '6';
s7 = '7';
s8 = '8';
s9 = '9';
}
PlayerTurn = 1;
} else {
if (PlayerTurn == 1) {
PlayerTurn = 2;
} else {
PlayerTurn = 1;
}
}
}
while (!GameOverDecider) {
if (Option == 2) {
cout << "Ok....." << endl;
}
return (0);
}
}
}
}
the error occurs right after the "return (0);}" line, and I don't know what else to do.
Upvotes: 0
Views: 173
Reputation: 780984
On the line after
if (Option == 1) {
you have do {
. But there's no while
or until
condition at the end of that block. It looks like it should be
do {
...
} while (!GameOverDecider);
And then the code inside that erroneous while
loop should not be in side it, it should be at the same level as the first if
.
Upvotes: 0
Reputation: 1500
Your while condition:
while (!GameOverDecider) {
if (Option == 2) {
cout << "Ok....." << endl;
}
return (0);
}
this one is inside the do
and once do is completed it can't get while and hence error. Reduce one brace among the 4 brackets present below and add 1 brace before this while.
Upvotes: 1