--- In [email protected], "thides" <[EMAIL PROTECTED]> wrote: > > --- In [email protected], Paul David <pauljdavid@> wrote: > > > > i have no idea what to do. it wont compile on my mac. WHAT AM I > DOING > > WRONG! > > > > here is the code it is in C++: > > > > #include <iostream> > > #include <ctime> > > using namespace std; > > int printboard(); > > > > char board[8][8] = { {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',}, > {' ', > > ' ', ' ', ' ', ' ', ' ', ' ', ' ',}, > {' ', ' ', ' ', ' ', ' ', ' ', ' > > ', ' ',}, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',}, > {' ', ' ', ' ', ' > > ', ' ', ' ', ' ', ' ',}, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',}, > {' > > ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',}, > {' ', ' ', ' ', ' ', ' ', ' ', > > ' ', ' ',}, }; > > What is this extra comma doing at the end of this initialization. > > > int main() > > { > > srand(time(NULL)); > > int pos1 = rand()%8; > > int pos2 = rand()%8; > > int pos3 = rand()%8; > > int pos4 = rand()%8; > > int loop = 1; > > char move; > > board[pos1][pos2] = '@'; > > board[pos3][pos4] = 'O'; > > while(loop=1) > > { > > printboard(); > > cout << endl << endl << "use W,A,S,D to move or Q to > quit: "; > > cin >> move; > > if((move == 'w') || (move == 'W')) > > { > > board[pos3][pos4] = ' '; > > pos4--; > > board[pos3][pos4] = 'O'; > > printboard(); > > cout << endl << endl; > > } > > if((move == 'a') || (move == 'A')) > > { > > board[pos3][pos4] = ' '; > > pos3--; > > board[pos3][pos4] = 'O'; > > printboard(); > > cout << endl << endl; > > } > > if((move == 's') || (move == 'S')) > > { > > board[pos3][pos4] = ' '; > > pos4++; > > board[pos3][pos4] = 'O'; > > printboard(); > > cout << endl << endl; > > } > > if((move == 'd') || (move == 'D')) > > { > > board[pos3][pos4] = ' '; > > pos3++; > > board[pos3][pos4] = 'O'; > > printboard(); > > cout << endl << endl; > > } > > if((move == 'q') || (move == 'Q')) > > { > > break; > > } > > if((board[pos1][pos2] == ' ') || (board[pos1][pos2] > == 'O')) > > { > > system("clear"); > > while(loop <= 1500) > > { > > cout << "YouWin! "; > > loop++; > > } > > system("sleep 3"); > > break; > > } > > if((move != 'w') && (move != 'W') && (move != 'a') && > (move != 'A') > > && (move != 's') && (move != 'S') && (move != 'd') && (move ! = 'D') > && > > (move != 'q') && (move != 'Q')) > > { > > cout << "enter W,A,S,D,Q" << endl; > > system("sleep 3"); > > system("clear"); > > clear has already been addressed in earlier posting. > > > printboard(); > > cout << endl << endl; > > } > > } > > } > > int printboard() > > { > > system("clear"); > > cout << "_" << "." << "_______" << "." << "_____" << "." > << "_____" > > << "." << "_____" << "." << "_____" << "." << "_____" << "." << > > "_____" << "." << "_____" << "._\n"; > > for(int i = 0;i < 8; i++) > > { > > cout << "_" << "| " << board[0][i] << " | " << board[1] > [i] << " > > | " << board[2][i] << " | " << board[3][i] << " | " << board > [4] > > [i] << " | " << board[5][i] << " | " << board[6][i] << " | " > << > > board[7][i] << " |_\n"; > > cout << "_" << "|" << "_______" << "|" << "_____" << "|" > << "_____" > > << "|" << "_____" << "|" << "_____" << "|" << "_____" << "|" << > > "_____" << "|" << "_____" << "|_\n"; > > } > > This took me a while as to the design for the board. I ended up > grouping them like this: > > cout << "_" << "| " << board[0][i] << " | " << board[1][i] << " | " > << board[2][i] << " | " << board[3][i] << " | " > << board[4][i] << " | " << board[5][i] << " | " > << board[6][i] << " | " << board[7][i] << " |_\n"; > cout << "_" << "|" << "_______" << "|" << "_____" << "|" << "_____" > << "|" << "_____" << "|" << "_____" << "|" << "_____" > << "|" << "_____" << "|" << "_____" << "|_\n"; > > It looks like the board is divided into squares except for the first > and last cout quote in both these statements. In these cases the > underscore(_) seems not to be needed. Also the underscore in the > second cout statement third quote seems to be out of line with the > rest of the layout. IMO Both of my statements above look easier to > read and able to detect errors quicker. I dont know what the rest of > the group thinks...? > > I also notice after each time printboard was called you added: > > cout << endl << endl; > > IMO it seems logical that this is part of the board and could go in > the printboard function. > > You have printboard and main returning an int. There seems to be no > return statements to return anything int or otherwise. > > Lastly, you have declared printboard at the beginning of the code. > This is necessary in C but in C++ you can if you like just type the > function as C++ can define and declare both above and below main(). > > > } > > > > [Non-text portions of this message have been removed] > > > > Some of these comments are not necessarily errors in the code but in > some cases allow others who might and will read the code an easier > time. > > Steve >
Well, it looked fine in preview... Why have a preview if it doesn't preview the way it looks online? I know nothing the group can do its Yahoo. Steve
