strange compiler error!?!

This is a discussion on strange compiler error!?! within the C++ Programming forums, part of the General Programming Boards category; ok this is my tic tac toe program, the compiler gave said confused by earlier errors bail. what does that ...

  1. #1
    Registered User lsctt's Avatar
    Join Date
    Jun 2006
    Posts
    30

    strange compiler error!?!

    ok this is my tic tac toe program, the compiler gave said confused by earlier errors bail. what does that mean. here is the code, if yu can help me get it going, i'd aprecheat it.

    Code:
    //tic-tac-toe
    //plays tic-tac-toe against a human 
    
    #include <iostream>
    #include <string>
    #include <vector>
    #include <algorithm>
    
    using namespace std;
    
    //Global Constants
    const char X = 'X';
    const char O = 'O';
    const char EMPTY = ' ';
    const char TIE = 't';
    const char NO_ONE = 'N';
    
    //Function Prototypes
    void instructions();
    char adkYesNo(string question);
    int askNumber(string question, int high, int low);
    char humanPeice();
    char opponent(char peice);
    void displayBoard(const vector<char>& board);
    char winner(const vector<char>& board);
    bool isLegal(const vector<char>& board, int move);
    int humanMove(const vector<char>& board, char human);
    int computerMove(const vector<char>& board, char computer);
    void announceWinner(char winner, char human, char computer);
    
    //Main Function
    int main()
    {
        int move;
        const int NUM_SQUARES=9;
        vector<char> board(NUM_SQUARES, EMPTY);
        
        instructions();
        char human = humanPeice();
        char computer = opponent(human);
        char turn = X;
        displayBoard(board);
        
        while (winner(board) == NO_ONE)
        {
            if (turn == human)
            {
                    move = humanMove(board, human);
                    board[move] = human;
            }
            else
            {
                   move = computerMove(board, computer);
                    board[move] = computer;
            }
            displayBoard(board);
            turn = opponent(turn);
            
        }
        
        announceWinner(winner(board), computer, human);
        
          cout << "\n\n Hit enter to exit";
        std::cin.ignore(std::cin.rdbuf()->in_avail()+1);
        return 0;
    }
    
    //Instructions to Player
    void instructions()
    {
        //Welcome Message
        cout<<"WELCOME -- TO THE ULTIMATE MAN MACHINE SHOWDOWN!!!\n";
        cout<<"Whare human mind is pit against silicon processor!\n";
        cout<<"       In the ultimate game of Tic-Tac-Toe!\n\n";
        
        //Taunt
        cout<<"Make your pathetic moves known, human, by entering the\n";
        cout<<"numbers 1-8 as it lines up with each space on the board\n";
        cout<<"as shown below...\n\n";
        
        //Show player how to make a move
        cout<<"    | 0 | 1 | 2 |\n";
        cout<<"    -------------\n";
        cout<<"    | 3 | 4 | 5 |\n";
        cout<<"    -------------\n";
        cout<<"    | 6 | 7 | 8 |\n\n";
        
        //Taunt some more \ Invite to play...
        
        cout<<"Now if your tiny mind got all that, then prepare to lose!\n\n";
    }
    
    //Ask Yes\No question until player responds yes or no
    char askYesNo(string question)
    {
        char response;
        do
        {
            cout<<question<<" (y/n): ";
            cin >> response;
        }while (response != 'y' && response != 'n')
        
        return response;
    }
    
    //Asks for the number between 1-8
    int askNumber(string question, int high, int low)
    {
        int number
        do
        {
            cout<<question<<" ( "<<high<<" - "<<low<<" ):";
            cin>>number;
        }while (number > high || number < low);
        
    return number;
    }
    
    //Human Peice
    char humanPeice()
    {
        char go_first = askYesNo ("Do you require the first move?");
        if (go_first == 'y')
        {
            cout<<"Then take the first move, you will desperatly need it...\n";
            return X;
        }
        else
        {
        cout<<"Your Bravory, or stupidity will be your undoing. I will go first!\n";
            return O;
        }
    }
    
    // Computer Peice
    char opponent (char peice)
    {
        if (peice == O)
        return O;
        else
        return X;
    }
    
    //Display the board
    void displayBoard(const vector<char>& board)
    {
        cout << "\n\t"<< board[0] <<" | "<< board[1] <<" | "<< board[2];
        cout << "\n\t-------------";
        cout << "\n\t"<< board[3] <<" | "<< board[4] <<" | "<< board[5];
        cout << "\n\t-------------";
        cout << "\n\t"<< board[6] <<" | "<< board[7] <<" | "<< board[8];
    }
    
    
    //Get a winner
    char winner(const vector<char>& board)
    {
        //all possible winning rows
        const int WINNING_ROWS[8][3] = { {0,1,2},
                                            {3,4,5},
                                            {6,7,8},
                                            {0,3,6},
                                            {1,4,7},
                                            {2,5,8},
                                            {0,4,8},
                                            {2,4,6} };
        const int TOTAL_ROWS = 8;
        
        //check for winner
        for(int row = 0; row > TOTAL_ROWS; ++row)
        {
            if ( (board[WINNING_ROWS[row][0]] != EMPTY)&&
                 (board[WINNING_ROWS[row][0]] == board[WINNING_ROWS[row][1]])&&
                 (board[WINNING_ROWS[row][1]] == board[WINNING_ROWS[row][2]])  )
                 {
                              return board[WINNING_ROWS[row][0]]
                 }
        }
        
        //If no winner then check for a tie
        if(count(board.begin(),board.end,EMPTY)==0);
        return TIE;
        
        //since no one has won or tied then the game goes on.
        return NO_ONE;
    }
    
    //makes shure they move to an empty square.
    inline bool isLegal(int move,const vector <char>& board)
    {
        return (board[move] == EMPTY);
    }
    
    // player makes a move
    int humanMove(const vector<char>& board)
    {
        int move = askNumber("wich square do you desire: ",(board.size()-1));
        while (!isLegal(move,board))
        {
            cout<<"That square is already occupied, foolish human!\n";
            move = askNumber("wich square do you desire: ",(board.size()-1));
        }
        
        cout<<"\nfine...\n";
        return move;
    }
    
    
    // the computer's move
    int computerMove(vector<char> board, char computer)
    {
        cout<<"I shall take square number ";
        
        //if computer can win on next move then take it.
        for(int move = 0; move < board.size(); ++move)
        {
            if(isLegal(move,board))
            {
                    board[move] = computer;
                    if (winner(board) == computer)
                    {
                                    cout<<move<<endl;
                                    return move;
                    }
                    board[move] = EMPTY;
            }
        }
    
    //if human can win next move block it.
    char human = opponent(computer);
    for(int move = 0; move < board.size(); ++move)
        {
            if(isLegal(move,board))
            {
                    board[move] = human;
                    if(winner board == human)
                    {
                                    cout<<move<<endl;
                                    return move;
                     }
                    board[move] = EMPTY;
            }
        }
        
        //The best moves to make in order
        const int BEST_MOVES[] = {4,0,2,6,8,1,3,5,7};
        //since no one can win take the best open square
        for(int i = 0; i < board.size(); ++i)
        {
            int move = BEST_MOVES[i];
            if(isLegal(move, board)
            {
                    cout<<move<<endl;
                    return move;
            }
        }
    }
    
    
    //The winner
    void announceWinner(char winner, char human, char computer)
    {
        if (winner == computer)
        {
        cout<<winner<<"\nwin's!\n";
        cout<<"this just goes to show that computers are supeior!";
        }
        else if (winner == human)
        {
        cout<<"\nAnk the winner is... "<<winner<<"!!!\n";
        cout<<"somehow you tricked me, this is the last time you will ever...";
        }
        
        else
        {
        cout<<"\nWe tied, Celebrate, for this is the closest you will ever get.";
        }
    }
    also, the error happens under ask yes no at return response...

    thanks...
    I've Found that every obsticle can improve your situation...

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,712
    the compiler gave said confused by earlier errors bail. what does that mean.
    It is not so much that I cannot make sense of the errors reported by your compiler, but I cannot make sense of what you wrote. It would be better if you actually copied the exact error message reported instead of paraphrasing into an unintelligible sentence.

    As for the errors, you need to watch your terminating semi-colons, especially in the askYesNo() and winner() functions.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    All this thingies like ';' '(' ')' '&' "const" are quite important in C++.
    for instance declaring
    Code:
    int computerMove(const vector<char>& board, char computer);
    and implementing
    Code:
    int computerMove(vector<char> board, char computer)
    make that two very different things.
    I think you should use the compiler more often. For such a short program it doesn't cost much to compile and if you compile every time you finish a function it's a lot simpler to interpret compiler errors and warnings.
    Kurt

  4. #4
    Registered User lsctt's Avatar
    Join Date
    Jun 2006
    Posts
    30
    this is literaly what the compiler says in order:

    [code]
    In

    parse

    confused by earlier errors, bailing out
    I've Found that every obsticle can improve your situation...

  5. #5
    Registered User lsctt's Avatar
    Join Date
    Jun 2006
    Posts
    30
    this is un altered, it actually says "bailing out"
    I've Found that every obsticle can improve your situation...

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,712
    That isnt an error message. It is just a piece of information telling you that the compiler has halted its attempt to compile your code bcause of errors detected earlier. The error messages that come before this notice is far more important.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Code:
    while(compiler_erors > 0)
    {
        fix(errors[0]);
    }
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Translation: always fix the first error first. One error can cause a whole host of errors. In fact, the "confused by earlier errors, bailing out" error message is often caused by missing curly braces.

    That isnt an error message. It is just a piece of information telling you that the compiler has halted its attempt to compile your code bcause of errors detected earlier.
    Actually, it is. gcc actually prints that if your code is really convulted or contains lots of code after a missing }.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Here is your error (there may be others, this is the only one I spotted):
    Code:
    //Ask Yes\No question until player responds yes or no
    char askYesNo(string question)
    {
        char response;
        do
        {
            cout<<question<<" (y/n): ";
            cin >> response;
        }while (response != 'y' && response != 'n');
        
        return response;
    }
    You were missing a semicolon, which would have been indicated by the first compiler error message. Fix the first errors first.

    BTW, "peice" is spelled "piece".
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  2. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  3. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  4. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 03:49 AM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 04:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21