Array for TicTacToe (2D)

Pages: 12
I wondered if I could ask for help again. Here is my question:

What expressions (as in math) are you supposed to use to get the array to check if someone won or lost the game? I understand that it is an IF and Else statement. I don't understand how to tell it so. I think it involves a counter statement...

I added some things but I still don't fully understand how to implement them correctly, I think.
I think she will allow functions now. if you guys have any advice, it would be appreciated.
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
#include <iostream>
#include <string>
using namespace std;
int main() 
{
		
		const int ROW = 3;
		const int COL = 3;
		char board[ROW][COL] = {' '};
		
		string playerName1;
		string playerName2;
		char playerTurn = 'x';
		int row;
		int col;
		//int check_for_winner;
		//int newgame;
		//int check_square;
		//int Play_again;
			
		//bool done = false;  I am trying to code it to end if someone wins
		//while(!done)

			cout << "Let's Play Tic Tac Toe!\n\n";
			cout << "Player 1, enter your name: ";
			cin >> playerName1;
			cout << "Your Letter is x, "  << playerName1 << ".\n\n";
			
			cout << "Player 2, enter your name: ";
			cin >> playerName2;
			cout << "Your Letter is o, "  << playerName2 << ".\n\n";
			

			do {
				cout << "  _O___1___2_\n";
				cout << "0| " << board[0][0] << " | " << board[0][1] << " | " << board[0][2] << " |\n";
				cout << " |___|___|___|\n";
				cout << "1| " << board[1][0] << " | " << board[1][1] << " | " << board[1][2] << " |\n";
				cout << " |___|___|___|\n";
				cout << "2| " << board[2][0] << " | " << board[2][1] << " | " << board[2][2] << " |\n";
				cout << " |___|___|___|\n";

				cout << "Enter the number for row first, hit the spacebar, and then enter the column number to choose a square to occupy.\n\n";
				cin >> row >> col;
			
				board [row][col] = playerTurn;
				if (playerTurn == 'x'){
					playerTurn ='o';
				}
				else {
					playerTurn = 'x';
				}
				
				{
				if( board[row][col] == ' ' ) // if the specified element (eg; 0 0) is empty,
					board[row][col] = playerTurn; // assign the player's symbol. (eg; X or O.)
					
				else
					cout << "Already taken!\n"; // else, notify the spot is taken. (endl is the same as "\n")
				}

				
				//for(int count = 0; count < 9; ++count)
				
			}
				while (true);
				
				
return 0;	

}





Last edited on
It's not exactly "math," but rather logic. The logic to determine if a player has won can be accomplished a few different ways.

When I wrote a TicTacToe game, I made a function that did three things:
Use a for loop to look at each row, if current player has each column in that row, return true. (This is for horizontal win.)

Use a for loop look at each column. (Works the same as the row loop, but reversed for vertical win.)

Use an if statement to check diagonal win. (Using the OR operator "||" to check both ways.)


To make function for this, you'll want to pass the board array and playerTurn to that function. Or you could do a if, else if, else if statement in your do while loop. You'll need to use "break;" to end the do while loop once someone has won for either way.

To make it easier to understand, I made a flowchart: http://www.majhost.com/gallery/Karkuta/pics/haswonfunction.png
Last edited on
Thanks Benjamind. Your sister is lucky to have a thoughtful brother like you! The flowChart was helpful. Thank you!
BejaminD,

On your flowchart there is a row/col < ARRAY_SIZE. What does this do? What does this say? I think I get the rest of it now.

Thanks,
Miscue
ARRAY_SIZE is a const int. I just used one variable for both the row and column since they were the same size. (Rather than declaring two const ints (ROW & COL) that both equal 3.)

the lower case row & col variables are for counters, for example I create row and start it at 0. Then while row is less than ARRAY_SIZE (3), we check all three columns in that row for the player's symbol. However I did forget to add the variable incrementation on those loops. >.< I'm so use to just using "for loops" that I forget to flowchart everything. :P I'll edit that real quick.
Last edited on
Erm.... I attempted to implement the flowchart with how I think it goes, and I believe that my code is probably very jumbled, and placed incorrectly in some spots.

You mean the ++ ( variable incrementation)? I didn't attempt to run my code because I am sure it is not right, and I didn't know what it would do. Thanks again for helping me! :-)

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
#include <iostream>
#include <string>
using namespace std;
int main() 
{
	
		const int ROW = 3;
		const int COL = 3;
		char board[ROW][COL] = {' '};
		
		string playerName1;
		string playerName2;
		char playerTurn = 'x';
		int row;
		int col;
		int hasWon;
		int newGame;
		int checkBoard;
		
			
		

			cout << "Let's Play Tic Tac Toe!\n\n";
			cout << "Player 1, enter your name: ";
			cin >> playerName1;
			cout << "Your Letter is x, "  << playerName1 << ".\n\n";
			
			cout << "Player 2, enter your name: ";
			cin >> playerName2;
			cout << "Your Letter is o, "  << playerName2 << ".\n\n";
			

			do {
				cout << "  _O___1___2_\n";
				cout << "0| " << board[0][0] << " | " << board[0][1] << " | " << board[0][2] << " |\n";
				cout << " |___|___|___|\n";
				cout << "1| " << board[1][0] << " | " << board[1][1] << " | " << board[1][2] << " |\n";
				cout << " |___|___|___|\n";
				cout << "2| " << board[2][0] << " | " << board[2][1] << " | " << board[2][2] << " |\n";
				cout << " |___|___|___|\n";

				cout << "Enter the number for row first, hit the spacebar, and then enter the column number to choose a square to occupy.\n\n";
				cin >> row >> col;
			
				board [row][col] = playerTurn;
				if (playerTurn == 'x'){
					playerTurn ='o';
				}
				else {
					playerTurn = 'x';
				}
				
				{
				if( board[row][col] == ' ' ) {
					board[row][col] = playerTurn; 
				}
				
				if(row < board_size)	{
					hasWon = 0;
				}
					else if(board[row][0] == player && board[row][1] == player && board[row][2] == player){
								hasWon = 1;
						}
						

				if(col < board_size) {
					hasWon = 0;
				}
					else if(board[0][col] == player && board[1][col] == player && baord[2][col] == player){
						hasWon = 1;
				}
						  else if(board[0][0] == player) && 
								 (board[1][1] == player) && 
								 (board[2][2] == player) ||
								 (board[2][0] == player) &&
								 (board[1][1] == player) &&
								 (board[0][2] == Player) {
							 hasWon = 1;
					}
							
				//else
					//cout << "Already taken!\n"; //  the spot is taken - how do I do this?
				for(int count = 0; count < 9; ++count)
			}
				while (true);
				
				bool done = false;  // what does this say in english-and what if it is true instead?
				while(!done)
			}
return 0;	

}



It's pretty close to what I had done, it is sometimes hard to follow flowcharts. (Making complicated ones is hard too.)

In the flowchart, see how the flow of control goes back to the if statement if the second condition is false? That makes the first "if" a loop. So it's really a "while" statement instead of an "if."

1
2
3
4
5
6
7
8
int conditionOfSomeKind = 0;

while( condition is true ) {

do something in here.

Increment conditionOfSomeKind.
}


You also need to initiate row & col to 0 on lines 14 & 15.

I like using the "for" loop because it lets me keep everything together:

1
2
3
4
5
for(variable initialization;  condition;  increment variable  ) {

do something in here

}


So for the rows and columns you can do something like this:
1
2
3
4
5
6
7
8
9
10
for(int row = 0; row < ROW; row++) {

if(board[row][0] == player && board[row][1] == player && board[row][2] == player){

	hasWon = 1; // You could a bool variable here or a char and assign it the winner's symbol.

        break; // This ends the loop. Since we found three in a row, we don't need to check the other rows.
}

}


On lines 54-56 you have if the spot is empty, fill it with player's symbol. You can add an else statement there for the "Already taken!" message.

On line 85, you have "while(true);" I'm pretty sure this is where you want "count <=9", you can delete line 83. You'll want to make a count variable and set it to 0 somewhere with the rest of the variables declared in the beginning of the code. After all nine turns are taken, we want to do something depending if there's a winner or if it's a draw. (I'd delete the extra bracket on line 87-89, probably going to give you a syntax error.)


Have you thought about using functions yet? There's some documentation on functions on the site here: http://www.cplusplus.com/doc/tutorial/functions/ (at the bottom of the page there's a "next" button for the second half.) You can always ask us if you need help implementing functions.
Last edited on
I have thought about it, but I am worried about using them...I printed out the function tutorial at the beginning of class, and have read and re-read it. I read a chapter in my book about it, and I printed out this posting so I could see it in front of me (I found your explanation easier to understand because C++ seems to mix English with math). I haven't had a chance to re-work my code, but I am going to tonight.

Thanks again,
Miscue
BenjaminD,

when you refer to the while loop, which line of code are you referring to? I wondered if you would check my code and see if I got it right?

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 <iostream>
#include <string>
using namespace std;
int main() 
{
	
		const int ROW = 3;
		const int COL = 3;
		char board[ROW][COL] = {' '};
		
		string playerName1;
		string playerName2;
		char playerTurn = 'x';
		int row = 0;
		int col = 0;
		bool hasWon();
		int checkBoard = 0;
		int count = 0;	
		

			cout << "Let's Play Tic Tac Toe!\n\n";
			cout << "Player 1, enter your name: ";
			cin >> playerName1;
			cout << "Your Letter is x, "  << playerName1 << ".\n\n";
			
			cout << "Player 2, enter your name: ";
			cin >> playerName2;
			cout << "Your Letter is o, "  << playerName2 << ".\n\n";
			

			do {
				cout << "  _O___1___2_\n";
				cout << "0| " << board[0][0] << " | " << board[0][1] << " | " << board[0][2] << " |\n";
				cout << " |___|___|___|\n";
				cout << "1| " << board[1][0] << " | " << board[1][1] << " | " << board[1][2] << " |\n";
				cout << " |___|___|___|\n";
				cout << "2| " << board[2][0] << " | " << board[2][1] << " | " << board[2][2] << " |\n";
				cout << " |___|___|___|\n";

				cout << "Enter the number for row first, hit the spacebar, and then enter the column number to choose a square to occupy.\n\n";
				cin >> row >> col;
			
				board [row][col] = playerTurn;
				if (playerTurn == 'x'){
					playerTurn ='o';
				}
				else {
					playerTurn = 'x';
				}
				
				{
				if( board[row][col] == ' ' ) {
					board[row][col] = playerTurn; 
				}
					
				while(row < 3) {
						do checkBoard;  // I don't think this is right!
				}

				for(int row =  0; row < ROW; row++) {
					    if(board[row][0] == player && board[row][1] == player && board[row][2] == player){
								hasWon = (true);
									cout << "Great job, you won !" << playerName << "\n";
										break;
						}
						

				if(col < board_size) {
					hasWon = 0;
				}
					else if(board[0][col] == player && board[1][col] == player && baord[2][col] == player){
						hasWon = 1;
				}
						  else if(board[0][0] == player) && 
								 (board[1][1] == player) && 
								 (board[2][2] == player) ||
								 (board[2][0] == player) &&
								 (board[1][1] == player) &&
								 (board[0][2] == Player) {
								  hasWon = 1;
					}
							
				else
					cout << "Already taken!\n"; //  the spot is taken -not sure how to code this
					
					for(int count = 0; count < 9; ++count)
						while(count <= 9);
			}
				
				
				bool hasWon = false;  // is this what you meant?
			
return 0;	

}


I still think it may be a little off, but I am getting there.

Thanks,
Miscue
Sorry is took a while to get back to you, was away visiting my older sister.

When I referring to while loops in my previous post, I was talking about the lines of code that check the array for three in a row. (Lines 56-81)

To show how I used functions (and to help with the game logic,) I'm including the Function Prototypes (which just declare the function so they can be defined after main(). ) and the main() function of a TicTacToe game I wrote.
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
96
97
//  =============
//  Header Files.
//  ==================
   #include <iostream>
   #include <windows.h> // This if for the ClearScreen() function I used made by Duoas.
   #include <string>
//  ================

//  =====================
//  Namespace Inclusions.
//  =====================
    using namespace std;
//  ====================

//  =======================
//  Constants Declarations.
//  =========================
    const int ARRAY_SIZE = 3; // We use one constant for both row and col.
//  =========================

//  ====================
//  Function Prototypes.
//  ========================================
    void PrintDisplay( char[][ARRAY_SIZE] );       // Prints the Board.
                                                   //Instead of ClearScreen() you could use system("CLS"); But it's not recommended for professional use. (Programs you'd actually distribute and stuff.) 

    void InitializeArray( char[][ARRAY_SIZE] );    // Fills all elements with a blank space.

    void Banner();                                 // Prints a welcome screen.
                                                   // Banner() is called within PrintDisplay().

    void Place( char, int&, char[][ARRAY_SIZE] );  // Makes the the player's move.

    bool HasWon( char, char[][ARRAY_SIZE] );       // Determines if a player has won.

    bool GoAgain();                                // Asks if player want to play another game.

    void ClearScreen();                            // Clears the screen so the new board can be drawn.
                                                   // ClearScreen() is called within PrintDisplay().
//  ===================

//  =============
    int main( ) {

        char gameField[ARRAY_SIZE][ARRAY_SIZE]; // Creates the board.

        do { // First loop for if player's want to play again.

            char playerSymbol = 'X'; // Player X is first.

            char winner = ' '; // Sets winner to blank.

            int turn = 0; // Sets turns to 0.

            bool gameOver = false; // Sets gameOver to false, since we're starting a new game.

            InitializeArray( gameField ); // Calls the function to set the board to blank spaces.

            PrintDisplay( gameField ); // Prints the Banner and board.

            do { // Loop for making turns.

                Place(playerSymbol, turn, gameField ); // Asks for player's choice and places it into the board, increases turn by 1.

                PrintDisplay( gameField ); // Clears the screen and reprints the board with player's move.

                if( HasWon(playerSymbol, gameField) ) { // Finds out if a player has won yet.

                    winner = playerSymbol; // If ture, we give winner the value of current player.
                    break; // Ends the turns loop
                }

                if(turn == 9) // If all nine turns have been made:
                    gameOver = true; // The game is over.

                else if(playerSymbol == 'O') { // if not over:
                    playerSymbol = 'X'; 
                }                              // We switch players.
                else {
                    playerSymbol = 'O';
                }

        }while( !gameOver ); // Continue this loop as long as game is not over.

            if(winner != ' ') { // If winner is not blank:
                cout << "Player " << winner << " won!" << endl; // Print the winner!
            }
            else {
                cout << "Cat game! Nobody won!" << endl; // Otherwise, no one won...
            }

        }while(GoAgain()); // Asks if players want to play again.

        return 0; // If not, quit program.

    } // function main()
//  ==================== 


Functions help break down the program into smaller and easier to manage pieces of code. Think of each function as a different tool, or a section of a symphonic band. Each function has a different task and combined they accomplish the bigger goal.

If there's a certain part of using functions you're having trouble with, feel free to ask.
Last edited on
Thank you BenjaminD, sorry It took me so long to respond myself...I had finals and a couple of projects.


I decided not to use functions, and here is what I have. It is due tomorrow. It works, but won't recognize a winner and end the game. I added some stuff from above. If you or anyone can help, please feel free to give me advice.

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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <iostream>
#include <string>

using namespace std;

int main() 
{
	
		const int ROW = 3;
		const int COL = 3;
		char board[ROW][COL] = {' '};
		string playerName1;
		string playerName2;
		string gameOver;
		string goAgain;
		char playerTurn = 'x';
		int row = 0;
		int col = 0;
		bool hasWon = false;
		int count = 0;	
		

			cout << "Let's Play Tic Tac Toe!\n\n";
			cout << "Player 1, enter your name: ";
			cin >> playerName1;
			cout << "Your Letter is x, "  << playerName1 << ".\n\n";
			
			cout << "Player 2, enter your name: ";
			cin >> playerName2;
			cout << "Your Letter is o, "  << playerName2 << ".\n\n";
			

			do {
				cout << "  _O___1___2_\n";
				cout << "0| " << board[0][0] << " | " << board[0][1] << " | " << board[0][2] << " |\n";
				cout << " |___|___|___|\n";
				cout << "1| " << board[1][0] << " | " << board[1][1] << " | " << board[1][2] << " |\n";
				cout << " |___|___|___|\n";
				cout << "2| " << board[2][0] << " | " << board[2][1] << " | " << board[2][2] << " |\n";
				cout << " |___|___|___|\n";

				cout << "Enter the number for row first, hit the spacebar, and then enter the column number to choose a square to occupy.\n\n";
				cin >> row >> col;
			
				board [row][col] = playerTurn;
				if (playerTurn == 'x'){
					playerTurn ='o';
				}
				else {
					playerTurn = 'x';
				}
				
				
				if(board[row][col] == ' ') {
					board[row][col] = playerTurn; 
				}
					
				for(int row =  0; row < ROW; row++) {
					    if((board[row][0] == playerTurn) && (board[row][1] == playerTurn) && (board[row][2] == playerTurn)){
						   hasWon = true;
							cout << "Great job, you won!";
									break;
						}
				}
				
				for(int col = 0; col < COL; col++) {
					    if((board[col][0] == playerTurn) && (board[col][1] == playerTurn) && (board[col][2] == playerTurn)){
						   hasWon = true;
							cout << "Great job, you won!";
									break;
						}
				}
								
					 if((board[0][col] == playerTurn) && (board[1][col] == playerTurn) && (board[2][col] == playerTurn)){
						hasWon = true;
						cout << "Great job, you won!";
									break;
					 }

						if(((board[0][0] == playerTurn) && (board[1][1] == playerTurn) && (board[2][2] == playerTurn)) || 
						  ((board[2][0] == playerTurn) && (board[1][1] == playerTurn) && (board[0][2] == playerTurn))) {
							hasWon = true;
								cout << "Great job, you won!";
									break;
					}
				}
						
				while(count <= 9);{
					hasWon = false;
				
					if(count == 9){ // If all nine turns have been made:
					    hasWon = true; // The game is over.
						   cout << "Game Over!";
					}	   break;
				}
					
				while( !gameOver ); // Continue this loop as long as game is not over.
				
						if(hasWon != ' ') { // If winner is not blank:
								cout << "You won!" << endl; // Print the winner!
						}

								else {
									cout << "It's a Tie! Nobody won!" << endl; // Otherwise, no one won...
								}

								while(goAgain()); // Asks if players want to play again.

				return 0;	
}
miscue, it's looking great!!

In the last post you never increment "count". I see "while(count <= 9)" and "if(count == 9)" but there's never a "count++" to change its value.
Thanks Emilya! Some of the code, particularly at the end with the while statements was stuff BenjaminD helped with.

What does the counter do in this instance, or rather what is it supposed to do?

Would you mind looking at one other assignment for me to see if it looks ok?


Thanks,
Emilya!
I have some code in the int main that is not showing up. It is due tomorrow. Could you take a look at this other program?

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
96
97
98
99
100
101
102
103
104
105
106
107
#include <iostream>
#include <string>

using namespace std;

class Employee {
private:
	
	
	int hours;
	int wages;
	int tax = 0.25;
	string employeeName;
	string netPay;

public:

	Employee() {
		setHours(1);
		setWages(1);
		setTax(.75);
		
	}
	
	Employee(int hours, int wages) {
		setHours(hours);
		setWages(wages);
		setTax(tax);
	}

	void setWages(int wages) {
		if (wages >= 1){
			this->wages = wages;
		} else {
			cout << "Invalid amount of wages entered." << endl;
		}
	}

	void setHours(int hours) {
		if (hours >= 1) {
			this->hours = hours;
		} else {
			cout << "Invalid number of hours entered." << endl;
		}
	}

	void setTax(int tax) {
		if (tax == .25) {
			this->tax = tax;
		} else {
			cout << "Invalid amount of tax entered." << endl;
		}
	}

	int getWages() {
		return wages;
	}

	int getHours() {
		return hours;
	}

	int getPay() {
		return grosspay = hours * wages;
	}

	int getTax() {
		return netpay = grosspay - (grosspay * .25);
	}

	void retrieve() {
		int temp;
		
		cout << "Enter Hours: ";
		cin >> temp;
		setHours(temp);
	
		cout << "Enter Wages: ";
		cin >> temp;
		setWages(temp);

		cout << "Calculating tax rate of 25%.";
		cin >> temp;
		setTax(temp);
	}

}


int main() {
	
	// none of this for the name or information is showing up---?
			cout << "Enter your name: ";
			cin >> employeeName;
			cout <<" " << employeeName << ", I will calculate your pay for the number of hours you worked.\n\n";
			cout << "Enter your information, "  << employeeName << ".\n\n";
			Employee empl;
			empl.retrieve();

// this part shows up
                        cout << "Hours: " << empl.getHours() << endl;
			cout << "Wages: " << empl.getWages() << endl;
			cout << "Gross Pay: " << empl.getPay() << endl;
			cout << "Net Pay: " << empl.getTax() << endl;

return 0;
}



What do you think?
I don't know about the employee program...I'm on a phone and can't take a good look. On your tic tac, the counter appears to be keeping track of the number of turns that have occurred. it is looking for the number 9, and uses that to indicate that the board is full. So you want to increment it each time a turn is successfully taken.
Sorry I could not get back to you sooner, my brother's birthday was today.

The TicTacToe code is looking really good so far. (You should add "count++;" at line 52.) Though a couple thing aren't working at the bottom:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
				while(count <= 9);{ //<-- This bracket should not exist.
					hasWon = false; //<-- This also shouldn't exist.
				
					if(count == 9){ // If all nine turns have been made: 
					    hasWon = true; // The game is over.
						   cout << "Game Over!";
					}	   break;
				}// ^ These lines are no longer necessary because you have it taken care of it with the while loop.
					
				while( !gameOver ); //<-- This line doesn't do anything.
				
						if(hasWon != ' ') { // If winner is not blank: //<-- hasWon is of type bool, not char. so it should say if(hasWon == true )
								cout << "You won!" << endl; // Print the winner!
						}

								else {
									cout << "It's a Tie! Nobody won!" << endl; // Otherwise, no one won...
								}

								while(goAgain()); // Asks if players want to play again. //<-- This line isn't necessary since you aren't using functions and asking the players to play again isn't required of the assignment.

				return 0;	
}


It should look more this is after "while(count <=9);"
1
2
3
4
5
6
7
8
9
if(hasWon == true)
    cout << "You won!" << endl; // Print the winner!
else 
    cout << "It's a Tie! Nobody won!" << endl; // Otherwise, no one won...

return 0;

//Don't forget to add main's closing bracket "}" here.
                     


Because the "if(hasWon == true)" code takes care of the "You won!" message, it probably isn't necessary to print it in lines 58-86. Lines 14-15 are no longer required either.

On your Employee program. I'm afraid I'm not quite familiar with classes just yet, but on line 25 you don't have the function type declared.
Last edited on
Thank you BenjaminD, and Happy Birthday to your brother! I got it fixed and turned it in! Thank you!

Thank you Emilya! Both of you were very helpful! I will mark this as solved. Happy holidays to both of you!

Without your help, I would not have been able to complete some of my assignments. Thank you!
Topic archived. No new replies allowed.
Pages: 12