Changing an input to output a "space"
Feb 26, 2013 at 12:32am Feb 26, 2013 at 12:32am UTC
I've been fumbling around with making this tic tac toe program work correctly. When the user inputs a " . " (period) in the array, i need it to just print a blank space.
eg:
input:
oxo
.xo
.xo
output:
O X O
_ X O
_ X O
underscores were to show formatting on the forum
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
void input (char board [3][3]);
void print (char board [3][3]);
bool win (char board [3][3], char player);
int main(int argc, char *argv[])
{
char board [3][3];
cout << "Enter your board as characters (x,o or .)" << endl;
cout << endl;
input(board);
print(board);
system("PAUSE" );
return EXIT_SUCCESS;
}
void input (char board [3][3])
{
int row;
int col;
for (row=0; row<3; row++)
for (col=0; col<3; col++)
cin>>board[row][col];
cout << endl;
}
void print (char board [3][3])
{
cout << "The Board is: " << endl;
cout << endl;
int r, c;
for (r = 0; r < 3; r++)
{
for (c = 0; c < 3; c++)
{
cout << " " << setw(1)<< board [r][c];
if (c<2) cout << " |" ;
}
cout << endl;
if (r<2)
{
cout <<"-----------" << endl;
}
}
cout << endl;
}
bool win (char board [3][3], char player)
{
}
Feb 26, 2013 at 12:37am Feb 26, 2013 at 12:37am UTC
Change it on the output?
1 2 3 4
if ( board[ row ][ column ] == '.' )
std::cout << ' ' ;
else
std::cout << board[ row ][ coloum ];
Last edited on Feb 26, 2013 at 12:37am Feb 26, 2013 at 12:37am UTC
Feb 26, 2013 at 12:45am Feb 26, 2013 at 12:45am UTC
Thank you Lynx876. After using what you said and putting it in the nested for loops in the print function, I got it to print blank spaces throughout the array if the whole thing is filled with period.
Feb 26, 2013 at 12:48am Feb 26, 2013 at 12:48am UTC
No problem. (:
Topic archived. No new replies allowed.