I cannot get this to print out correctly, when there is a tie in the game of tic tac toe. When there is a tie, it prints out both
1 2 3 4
if (finished == 'x')
cout << "You Have Defeated Me, this is impossible!!!! Let us Play Again....\n";
else
cout << "I have defeated you, I always said Machines Would become better than Humans at their own games. HAHAHA \n\n" << endl;
int main(void)
{
char finished; char c;
bool keep_playing = true;
cout << "Shall We Play A Game Today? \n Yes or No. (Y,N)" << endl;
string p;
cin >> p;
if (p == "Y" || p == "y")
{
system("cls");
cout << "Welcome To Tic Tac Toe \n\n" << endl;
cout << "The Human Player will be the X, during this game \n\n" << endl;
cout << "Here is how to play the game: \n\n 1) You must first enter which row you would like--from top to bottom. i.e. 1,2,3 and then press enter \n 2) Enter which column you would like, and press enter again. \n Good luck player \n\n" << endl;
while (keep_playing)
{
finished = ' ';
createboard();
do {
displayboard();
humanplayermove();
finished = checkforwinner(); /* check winner */
if (finished != ' ') break; /* if winner found...*/
computermove();
finished = checkforwinner(); /* check for winner again */
if (finished != ' ') break; /* if winner found...*/
if (checkforadraw(board)) //we don't have a winner and there are no open spaces.
{
displayboard();
cout << endl;
cout << "The Game has Ended in a Tie, surely you will want to play at least until someone wins human!!\n";
break;
}
newgameboard();
} while (finished == ' ');
if (finished == 'x')
cout << "You Have Defeated Me, this is impossible!!!! Let us Play Again....\n";
else
cout << "I have defeated you, I always said Machines Would become better than Humans at their own games. HAHAHA \n\n" << endl;
displayboard(); /* show final positions */
cout << "Would You like to go for another round? Y/N" << endl; cin >> c;
if (c == 'N' || c == 'n')
keep_playing = false;
newgameboard();
}
}
else cout << "Maybe Next Time You will be brave enough to face me." << endl;
return 0;
}
Im not a 100% sure but I would try using { } around the content i would want to print. For example:
if (finished == 'x'){
cout << "You Have Defeated Me, this is impossible!!!! Let us Play Again....\n";
}
else{
cout << "I have defeated you, I always said Machines Would become better than Humans at their own games.
}
From what I understand it would be like putting the content in scope of the if statement.
that worked great!!!!!!!!!!!!!!!! thank you so much!!! Seriously, I have been messing with that forever. Now if I could just get this animated that would be awesome. I will do a different post for that. Thank you so much again
its still not printing out correctly. Spook to soon. NO idea why it is doing that. It does the do while loop and then comes out, but is printing both statements from the if statement, which makes no sense.