| | |
help if possible (asap)
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Oct 2005
Posts: 62
Reputation:
Solved Threads: 0
my code was working, but when i added in a new section to enter playing against a computer player, it now hates me, and wont stop trying to kill me.
errors i am gettign are :
parse errors on lines 85,102,111,121,307
im also getting told that "IOS C++ forbids decleration of..." on lines 109, 110, 118, 120
there are also other errors withing that part of the code, what is weird to me however, is that it works perfectly fine in the other place that the almost identical code is placed (status 2)
c++ Syntax (Toggle Plain Text)
//name: ******* //Lab: * //purpose: ******* //modification date:*********** #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const int ROW=6, COL=8; const char player1 = 'O'; const char player2 = 'X'; void drawHeader(); void drawBoard(char board[ROW][COL]); void initialiseBoard(char board[ROW][COL]); int playerMove(char board[ROW][COL], char, int); int againstComputer(char board[ROW][COL], char, int); char chooseOption(); char quitGame(char); int computerMove(int); int main() { int status=1; // 1 for start or restart, 2 for play, 3 for quit char board[ROW][COL]; char option, playerChar, startAgain = 'y'; int move, playerNum; drawHeader(); do { if (status==1) //Just start or Restart { playerNum=1; option = chooseOption(); if (option=='a') { status = 3; // play against computer } else if (option=='b') { status = 2; //game play } else if (option=='c')//option is 'q' { status=4; } else cout << "Invalid Choice!"; } else if (status==2) //playing { do { if (startAgain == 'y') { initialiseBoard(board); playerNum = 1; startAgain = 'n'; } if (playerNum == 1) playerChar = player1; else playerChar = player2; drawBoard(board); move = playerMove(board, playerChar, playerNum); if (move==-1) { // no switch } else (move != 0) { if (playerNum == 0) playerNum = 1; else playerNum = 0; } else { startAgain = quitGame('y'); if (startAgain == 'n') status=4; else if (startAgain == 'y') status=2; } }while (status == 2); } else if (status == 3)//this is the new section that doesnt like working { do { if (startAgain == 'y') { initialiseBoard(board); playerNum = 1; startAgain = 'n'; } if (playerNum == 1) playerChar = player1; else playerChar = player2; drawBoard(board); move = againstComputer(board, playerChar, playerNum); if (move==-1) { } else (move != 0) { if (playerNum == 0) playerNum = 1; else playerNum = 0; } else { startAgain = quitGame('y'); if (startAgain == 'n') status=4; else if (startAgain == 'y') status=3; } }while (status ==3); } }while (status!=4); cout << "\nThanks for playing Connect Four, the game of the clever people!" << endl; return 0; } void drawHeader() { cout << "*********************************************************" << endl; cout << "* Connect Four *" << endl; cout << "*********************************************************" << endl; cout << "Welcome to the Connect Four computer game. You can choose" << endl; cout << "to play against another player or against the computer " << endl; cout << "(not implemented in this version)." << endl; cout << "In this game the first player to position four of his/her" << endl; cout << "pieces on a line will win. The line can be horizontal," << endl; cout << "vertical or at an angle, but the 4 pieces must be next to" << endl; cout << "each other." << endl; cout << "*********************************************************" << endl; return; } char chooseOption() { char option; cout << "\n*************************************" << endl; cout << "* Choose an Option *" << endl; cout << "*************************************" << endl; cout << "* a) Play against the computer *" << endl; cout << "* b) Play against another Player *" << endl; cout << "* c) Quit *" << endl; cout << "*************************************" << endl; cout << "Enter your choice: "; cin >> option; return option; } char quitGame(char quit) { char cont, startAgain; if (quit == 'y') { cout << "Do you want to start a new game (y/n)?: "; cin >> cont; cin.clear(); cin.ignore(300, '\n'); while ((cont != 'y') && (cont != 'n')) { cout << "Do you want to start a new game (y/n)?: "; cin >> cont; cin.clear(); cin.ignore(300, '\n'); } if (cont =='y') startAgain = 'y'; else startAgain = 'n'; } return startAgain; } void initialiseBoard(char board[ROW][COL]) { char rowComp = 0, colComp = 0; while(rowComp < ROW) { while(colComp < COL) { board[rowComp][colComp] = '.'; ++colComp; } colComp = 0; rowComp++; } return; } void drawBoard(char board[ROW][COL]) { char rowComp = 0, colComp = 0; while(rowComp < ROW) { while(colComp < COL) { cout << board[rowComp][colComp]; ++colComp; } cout << endl; colComp = 0; rowComp++; } cout << "12345678" << endl; return; } int playerMove(char board[ROW][COL], char playerChar, int playerNum) { int move, index = 5, position; bool cont = false; cout << (playerNum == 1 ? "Player 1" : "Player 2") << " move (1-8, 0 to quit): "; cin >> move; if ((move != 0) && ((move>=1) && (move<=8))) { do { position = move - 1; if (board[index][position] != '.') { if (--index == -1) { cout << "Sorry no more room in this column..." << endl; return -1; } } else cont = true; } while (!cont); board[index][position] = playerChar; } else if (move == 0) { cont = true; } else { cout << "This move is not allowed!" << endl; return -1; } return move; } int againstComputer(char board[ROW][COL], char playerChar, int playerNum) { int move, index = 5, position, cMove; bool cont = false; cout << (playerNum == 1 ? "Player 1" : "Computer") << " move (1-8, 0 to quit): "; if (playerNum != 1) computerMove(cMove); move = cMove; else cin >> move; if ((move != 0) && ((move>=1) && (move<=8))) { do { position = move - 1; if (board[index][position] != '.') { if (--index == -1) { cout << "Sorry no more room in this column..." << endl; return -1; } } else cont = true; } while (!cont); board[index][position] = playerChar; } else if (move == 0) { cont = true; } else { cout << "This move is not allowed!" << endl; return -1; } return move; } int computerMove(int cMove) { srand ( time(NULL) ); cMove= rand() % 8 + 1; return cMove; }
errors i am gettign are :
parse errors on lines 85,102,111,121,307
im also getting told that "IOS C++ forbids decleration of..." on lines 109, 110, 118, 120
there are also other errors withing that part of the code, what is weird to me however, is that it works perfectly fine in the other place that the almost identical code is placed (status 2)
![]() |
Similar Threads
- I feel sick... Hard drive not found... need help asap =( (Troubleshooting Dead Machines)
- Need Help ASAP.. iMac(blue and white) wont eject the cd (Apple Hardware)
- Need Help ASAP.. iMac(blue and white) wont eject the cd (Troubleshooting Dead Machines)
- Need x86 assembly programmer ASAP ! (Assembly)
- Very New to Java and need help converting cubic inches to cm (Java)
Other Threads in the C++ Forum
- Previous Thread: different C++ versions. suspected dll incompattibility
- Next Thread: Hash Table display problem
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api array arrays based beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number output pointer problem program programming project python random read recursion recursive reference rpg simple string strings system temperature template templates test text text-file tree unix url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






