• Advertisement
Sign in to follow this  

5-1-10.cpp(148) : error C2059: syntax error : ''

This topic is 2853 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#include<iostream> #include<string> using namespace std; const int red = 100; const int black = 305; const int king = 2000; int board[8][8]; const int startup[8][8] = { red, 0, red, 0, red, 0, red, 0, 0, red,0,red,0,red,0, red, red, 0, red, 0, red, 0, red, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -black, 0, -black, 0, -black, 0, -black, -black, 0, -black, -0, -black, 0, -black, 0, 0, -black, 0, -black, 0, -black, 0, -black}; void setup (void) { int i, j; for (i = 0; i < 8; i++){ for (j = 0; j < 8; j++){ board[j] = startup[j]; } } } void printb (void){ using namespace std; int a, b; string piece; for (a = 7; a > -1; a--){ cout << endl; for (b = 0; b < 8; b++){ switch (board[a]){ case 0: piece = "-"; break; case red: piece = "r"; break; case black: piece = "b"; break; case king: piece = "K"; break; case -red: piece = "r"; break; case -black: piece = "b"; break; case -king: piece = "k"; break; } cout << " " << piece << " "; } } cout << endl << endl; } int main (void) { using namespace std; int iPlayerTurn(1); bool bGameOver(true); cout << "Welcome to Checkers!" << endl << "Created by Eddie" << endl << endl; cout << "Please Enter Your Moves In 4 Letter Algebraic" << endl << "i.e. e2e4 in lower case only" << endl; cout << "Commands: exit = quit, abort = quit, print = displays the board," << endl << "new = new game" << endl << endl; std::cout << "Player" << iPlayerTurn << "'s move:" << std::endl; bool bValidMove; string passd; setup(); while (1){ getline (cin, passd); if (passd.substr(0, 4) == "exit" || passd.substr(0, 5) == "abort" || passd.substr(0, 4) == "quit") if (passd.substr(0, 5) == "print") { printb(); } if (passd.substr(0, 3) == "new") setup (); if (passd.substr(0,4) == "exit" || passd.substr(0,4) == "quit") break; if (passd.substr(0, 1) >= "a" && passd.substr(0, 1) <= "h" && passd.substr(1, 1) >= "1" && passd.substr(1, 1) <= "8" && passd.substr(2, 1) >= "a" && passd.substr(2, 1) <= "h" && passd.substr(3, 1) >= "1" && passd.substr(3, 1) <= "8") if(passd[2] == passd[0]+1 && passd[3] == passd[1]+1 || passd[2] == passd[0]-1 && passd[1] == passd[3]-1) cout<<"correct move"<<endl; else if(passd[2] == passd[0]-1 && passd[3] == passd[1]-1 || passd[2] == passd[0]+1 && passd[1] == passd[3]+1) cout<<"correct move"<<endl; else cout<<"wrong move"<<endl; char cPlayerMark; if (iPlayerTurn == 1){ cPlayerMark = 'X'; } else { cPlayerMark = 'O'; } do { char cNextMove; std::cin >> cNextMove; bValidMove = true; if (iPlayerTurn == 1) { iPlayerTurn = 2; } else iPlayerTurn = 1; int a, b, c, d; a = passd[0] - 'a'; b = passd[1] - '1'; c = passd[2] - 'a'; d = passd[3] - '1'; board[d][c] = board[a]; board[a] = 0; printb(); } }<-(the error) }

Share this post


Link to post
Share on other sites
Advertisement
Use [source][/source] tags for long blocks of code. You can use "code" tags for snippets that are only a handful of lines.

Also, it would be nicer to include the problem description in the thread body, the title should be just an overview.

Anyway, your problem is that there is no such thing as an infinite "do" loop in C++. You can use while(true) { /* ... */ }. More likely you will want some way of breaking the loop, such as a player wins and then chooses to quit. In this case, you can put that condition in the while(/* condition */) of either a standard "while" loop or in a "do { /* stuff */ } while( /* condition */ );" loop.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement