this
for(rowVar == 1 && colvar == 1;grid[0][0] == 'X' || grid[0][0] == 'O';choice++That did not work because as soon as I asked for the first entry my initialization statement was true ,but so was my test expression. It seems I cannot find a way to stop these loops.
Thank you in advance for any help as my assignment was due 12 minutes ago and I have been messing with this for going on a week.
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
//Global constants
const int rows = 3; //Rows on the game board
const int col = 3; //Columns on the game board
//Global variables
int choice,
choice1 = 0,
choice2 = 0,
choice3 = 0,
choice4 = 0,
choice5 = 0,
choice6 = 0,
choice7 = 0,
choice8 = 0,
choice9 = 0,
turnsAllowed = 9,
rowVar = 10, //used for player to select the row they want to mark
colVar = 10, //used for player to select the column the want to mark
Turn = 0; //used with exchanging turns equation line 80
bool winner = false;
//Function prototypes
void displayBoard(char [][col]);
//2D Array for the game board
char grid[rows][col];
int _tmain(int argc, _TCHAR* argv[])
{
//initialize the array
char grid[rows][col] = {{'*','*','*'},
{'*','*','*'},
{'*','*','*'}};
//call the board
displayBoard(grid);
//ask for row and column
cout << "\n";
cout << "Enter a row and column to place an X." << "\nRow: ";
cin >> rowVar;
cout << "\nColumn:";
cin >> colVar;
//grid[rowVar][colVar]; //enter the row and column
while( winner == false || choice < turnsAllowed )
{
for(rowVar == 1 && colVar == 1;choice1 < 1; choice1++)
{
if( Turn == 0 )
{
grid[0][0] = 'X';
displayBoard(grid);
cout << "\nEnter a row and column to place an O .";
}
else
{
grid[0][0] = 'O';
displayBoard(grid);
cout << "\nEnter a row and column to place an X .";
}
}
for(rowVar == 1 && colVar == 2;choice2 < 1; choice2++)
{
if( Turn == 0 )
{
grid[0][1] = 'X';
displayBoard(grid);
cout << "\nEnter a row and column to place an O .";
}
else
{
grid[0][1] = 'O';
displayBoard(grid);
cout << "\nEnter a row and column to place an X .";
}
}
//if(rowVar == 0 || colVar == 2)
for(rowVar == 1 && colVar == 3;choice3 < 1; choice3++)
{
if( Turn == 0 )
{
grid[0][2] = 'X';
displayBoard(grid);
cout << "\nEnter a row and column to place an O .";
}
else
{
grid[0][2] = 'O';
displayBoard(grid);
cout << "\nEnter a row and column to place an X .";
}
}
for(rowVar == 2 && colVar == 1;choice4 < 1; choice4++)
{
if( Turn == 0 )
{
grid[1][0] = 'X';
displayBoard(grid);
cout << "\nEnter a row and column to place an O .";
}
else
{
grid[1][0] = 'O';
displayBoard(grid);
cout << "\nEnter a row and column to place an X .";
}
}
for(rowVar == 2 && colVar == 2;choice5 < 1; choice5++)
{
if( Turn == 0 )
{
grid[1][1] = 'X';
displayBoard(grid);
cout << "\nEnter a row and column to place an O .";
}
else
{
grid[1][1] = 'O';
displayBoard(grid);
cout << "\nEnter a row and column to place an X .";
}
}
for(rowVar == 2 && colVar == 3;choice6 < 1; choice6++)
{
if( Turn == 0 )
{
grid[1][2] = 'X';
displayBoard(grid);
cout << "\nEnter a row and column to place an O .";
}
else
{
grid[1][2] = 'O';
displayBoard(grid);
cout << "\nEnter a row and column to place an X .";
}
}
for(rowVar == 3 && colVar == 1;choice7 < 1; choice7++)
{
if( Turn == 0 )
{
grid[2][0] = 'X';
displayBoard(grid);
cout << "\nEnter a row and column to place an O .";
}
else
{
grid[2][0] = 'O';
displayBoard(grid);
cout << "\nEnter a row and column to place an X .";
}
}
for(rowVar == 3 && colVar == 2;choice8 < 1; choice8++)
{
if( Turn == 0 )
{
grid[2][1] = 'X';
displayBoard(grid);
cout << "\nEnter a row and column to place an O .";
}
else
{
grid[2][1] = 'O';
displayBoard(grid);
cout << "\nEnter a row and column to place an X .";
}
}
for(rowVar == 3 && colVar == 3;choice9 < 1; choice9++)
{
if( Turn == 0 )
{
grid[2][2] = 'X';
displayBoard(grid);
cout << "\nEnter a row and column to place an O .";
}
else
{
grid[2][2] = 'O';
displayBoard(grid);
cout << "\nEnter a row and column to place an X .";
}
}
Turn = (Turn +1) % 2;
cout << "\nRow:";
cin >> rowVar;
cout << "\nColumn:";
cin >> colVar;
cout << "test3";
system("pause");
}
system("pause");
return 0;
}
//*******************************************************************************
//Definition of function showBoard *
//To print the game board *
//*******************************************************************************
void displayBoard(char grid[rows][col])
{
cout << " Columns\n";
cout << " 1 2 3\n";
cout << "Row 1: "<< grid[0][0] << " " << grid[0][1] << " " << grid[0][2] << endl;
cout << "Row 2: "<< grid[1][0] << " " << grid[1][1] << " " << grid[1][2] << endl;
cout << "Row 3: "<< grid[2][0] << " " << grid[2][1] << " " << grid[2][2];
}

New Topic/Question
Reply



MultiQuote





|