Sign in to follow this  
EdMyStEr

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

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[i][j] = startup[i][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][b]){ 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[b][a]; board[b][a] = 0; printb(); } }<-(the error) }

Share this post


Link to post
Share on other sites
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this