Sponsored Content
Full Discussion: C++ Help
Top Forums Programming C++ Help Post 302274462 by RossMc on Wednesday 7th of January 2009 03:55:00 PM
Old 01-07-2009
Quote:
Originally Posted by Corona688
My example replaces your entire while() loop. It's also just a bare skeleton, like I said; there's bits you need to fill in yourself. I'll comment it better to give you more idea what it's doing and what's not finished. I've also fixed some problems I just noticed in my first version.

Code:
char player='2'; /* Keeps track of who's playing */

/* Loop through this block until the game ends */
while(! gameover)
{
  int row, column;

  /* Put the stuff to print the board here */

  /* Switch players */
  if(player == '1')
  {
    player='2';
  }
  else 
  {
    player='1';
  }

  /* Print a message for the player */
  cout << "Player " << player << "'s turn:" << endl;
  /* Read two values from the keyboard */
  cin >> row >> column;
  /* Change the game board */
  board[row-1][column-1]=player;

  /* You need to check if the game's over. */
}

cout << "Player " << player << " wins!" << endl;

Thanks for the reply i don't think i have done it right but i have put the code in there and deleted some like this

Code:
#include <iostream>

#include <cstdlib>

#include <cstdio>

#include <limits>



using std::cout;

using std::cin;

using std::endl;

int main()

{

char a[] = {'|','_','|','_','|','_','|','_','|','_','|','_','|','_','|'};

char b[] = {'|','1','|','2','|','3','|','4','|','5','|','6','|','7','|'};

char board[6][7];

int i, j, k =0;

int row;

int column;

int game =1;



for (i=0; i<6; i++)

for (j=0; j<7; j++)

board[i][j] = ' ';

cout<<" ";

for( j = 0; j<15; j++)

cout <<b[j];

cout <<endl;

for ( i=0; i<6; i++)

{ cout <<i+1;

for( j = 0; j<15; j++)

cout <<a[j];

cout <<endl;

}

char player='2'; /* Keeps track of who's playing */

/* Loop through this block until the game ends */
while(! gameover)
{
  int row, column;

  /* Put the stuff to print the board here */

  /* Switch players */
  if(player == '1')
  {
    player='2';
  }
  else 
  {
    player='1';
  }

  /* Print a message for the player */
  cout << "Player " << player << "'s turn:" << endl;
  /* Read two values from the keyboard */
  cin >> row >> column;
  /* Change the game board */
  board[row-1][column-1]=player;

  /* You need to check if the game's over. */
}

cout << "Player " << player << " wins!" << endl;
}

cout <<endl;

}

k++;

if( k ==42){

game =0;

}

}

cout << "Game Over" <<endl;


return 0;

}

I get this error

board.cpp: In function ‘int main()':
board.cpp:66: error: ‘gameover' was not declared in this scope
board.cpp: At global scope:
board.cpp:95: error: expected constructor, destructor, or type conversion before ‘<<' token
board.cpp:97: error: expected declaration before ‘}' token

Is there bits i need to change because i don't really understand it

Thanks RossSmilie
 
All times are GMT -4. The time now is 06:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy