Aleena
Aleena

Reputation: 11

Unexpected unqualified-id before 'while'

Trying to make a BASIC TicTacToe game using OOP C++

The errors I'm getting are: line 74 unexpected unqualified-id before 'while' (1) line 139 error: expected '}' at end of input (2) line 77 error: expected unqualified-id at end of input (3)

I have no idea how those brackets could be wrong...Thank you in advance! Here is my code:

#include <iostream>
#include <stdlib.h>
using namespace std;

class TicTacToe
{
private:
int player=1, cw , ch1, ch2; //ch= choice for rows and columns
char pick, grid[10]= {' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
public:
int checkWin()
{
  if (grid[1] == grid[2] && grid[2] == grid[3])

    return 1;
else if (grid[4] == grid[5] && grid[5] == grid[6])

    return 1;
else if (grid[7] == grid[8] && grid[8] == grid[9])

    return 1;
else if (grid[1] == grid[4] && grid[4] == grid[7])

    return 1;
else if (grid[2] == grid[5] && grid[5] == grid[8])

    return 1;
else if (grid[3] == grid[6] && grid[6] == grid[9])

    return 1;
else if (grid[1] == grid[5] && grid[5] == grid[9])

    return 1;
else if (grid[3] == grid[5] && grid[5] == grid[7])

    return 1;
else if (grid[1] != '1' && grid[2] != '2' && grid[3] != '3'
                && grid[4] != '4' && grid[5] != '5' && grid[6] != '6'
              && grid[7] != '7' && grid[8] != '8' && grid[9] != '9')

    return 0;
else
    return -1;
}//check for winner
char mark()
{
    if(player==1)
       return 'X';
    else
       return 'O';
}
void board()
{
    system("cls");
cout << "\n\n\tTic Tac Toe\n\n"; //learned that \t is to tab it in instead    of using spaces

cout << "Player 1 = X    Player 2 = O" << endl << endl;
cout << endl;

cout << "   1     2    3  ";
cout <<"\n";
cout << "     |     |     " << endl;
cout << "1 " << grid[1] << "  |  " << grid[2] << "  |  " << grid[3] << endl;
cout << "     |     |     " << endl;
cout << "_____|_____|_____" << endl;
cout << "     |     |     " << endl;

cout << "2 " << grid[4] << "  |  " << grid[5] << "  |  " << grid[6] << endl;
cout << "     |     |     " << endl;
cout << "_____|_____|_____" << endl;
cout << "     |     |     " << endl;

cout << "3 " << grid[7] << "  |  " << grid[8] << "  |  " << grid[9] << endl;
cout << "     |     |     " << endl;
cout << "     |     |     " << endl << endl;

} // and for some reason this one (3)

while (i==-1) // **this one (1)**
{
    if(player %2)
        player==1
    else
        player==2
    cout<< "Please enter 1-3 for row: ";
    cin>> ch1;
    cout<< "Please enter 1-3 for coumns: ";
    cin>>ch2;

    mark();

    if(ch1=1 && ch2 ==1)
        mark = grid[1];
    else if (ch1=2 && ch2== 1)
        mark = grid[2];
    else if (ch1=3 && ch2== 1)
        mark = grid[3];
    else if (ch1=1 && ch2== 2)
        mark = grid[4];
    else if (ch1=2 && ch2== 2)
        mark = grid[5];
    else if (ch1=3 && ch2== 2)
        mark = grid[6];
    else if (ch1=1 && ch2== 3)
        mark = grid[7];
    else if (ch1=2 && ch2== 3)
        mark = grid[8];
    else if (ch1=3 && ch2== 3)
        mark = grid[9];
    else
    {
        cout<<" Move is invalid";
        player--; //so player can retake turn
        //cin.ignore(); //ignore what was input
        //cin.get(); // get answers
    }
       cw= checkwin();
}
board();
if(i==1)

    cout<<"\aPlayer "<<--player<<" win "; // a makes a beep!
else
    cout<<"\aGame draw";

//cin.ignore();
//cin.get();
return 0;


};

int main()
{
cout<<" \tWelcome to TicTacToe!";
TicTacToe game;
return 0;

} // **issue with this one (2)**

Upvotes: 1

Views: 5973

Answers (2)

user3742860
user3742860

Reputation: 100

you forgot to write ; at the end of a decleration:

    while(i == -1) // **this one (1)**
        {
            if (player % 2)
                player == 1
            else

AND


player == 2    //You forgot to write    ; 
        cout << "Please enter 1-3 for row: ";
        cin >> ch1;
        cout << "Please enter 1-3 for coumns: ";
        cin >> ch2;

this makes probems later in the code when stuff isn't found!

Upvotes: 0

Sadique
Sadique

Reputation: 22821

You ended your board function here:

cout << "     |     |     " << endl << endl;

} // and for some reason this one (3) <----PROBLEM is this Closing Brace

while (i==-1) // **this one (1)**

Upvotes: 3

Related Questions