Tic-Tac-Toe Challenge Project (C++)

Congratulations on completing your project!

Compare your project to our solution code and share your project below! Your solution might not look exactly like ours, and that’s okay! The most important thing right now is to get your code working as it should (you can always refactor more later). There are multiple ways to complete these projects and you should exercise your creative abilities in doing so.

This is a safe space for you to ask questions about any sample solution code and share your work with others! Simply reply to this thread to get the conversation started. Feedback is a vital component in getting better with coding and all ability levels are welcome here, so don’t be shy!

About community guidelines: This is a supportive and kind community of people learning and developing their skills. All comments here are expected to keep to our community guidelines

How do I share my own solutions?

  • If you completed the project off-platform, you can upload your project to your own GitHub and share the public link on the relevant project topic.
  • If you completed the project in the Codecademy learning environment, use the share code link at the bottom of your code editor to create a gist, and then share that link here.

Do I really need to get set up on GitHub?
Yes! Both of these sharing methods require you to get set up on GitHub, and trust us, it’s worth your time. Here’s why:

  1. Once you have your project in GitHub, you’ll be able to share proof of your work with potential employers, and link out to it on your CV.
  2. It’s a great opportunity to get your feet wet using a development tool that tech workers use on the job, every day.

Not sure how to get started? We’ve got you covered - read this article for the easiest way to get set up on GitHub.

Best practices for asking questions about the sample solution

  • Be specific! Reference exact line numbers and syntax so others are able to identify the area of the code you have questions about.


Please review my code and give me suggestion where improvement is required-

link:- https://gist.github.com/62412548267feaeff7593b568b701029

Revision001- https://gist.github.com/ffefe336a03fbb0d7fc2496c4464c803

Hi, my solution seem didn’t work. Because I’ve learnt the Reference Unit so I used reference in my solution because I think it will help me modify the variables outside the functions, so maybe that’s the reason why the code doesn’t work, but I’m not sure. Can anyone help me on fixing it and explain the errors I’ve made please? Thank you.
My solution: https://gist.github.com/7a2c40f419cfe2ba57d596589eefea83

This is my first challenge project. Hoping to build more.

1 Like

Please, could you review my code that would be really nice of you :slight_smile:

Took me a while but I got it. Still need to work on integrating other files and using a declaration page and another cpp file but I am getting there and will have it down soon.

1 Like

Hi, I don’t know what I’m doing wrong. Can anyone help? https://gist.github.com/408a0617611975785662984e9496e98b

My first game made. More to come!

Whoop! FInally understood and coded a C++ program!

It sure ain’t pretty but it works. Bring the noise.

Here we go, my first C++ program!

It has a weird issue I can’t quite pin down. While waiting for the user input, if you hit a directional key before a number, it ends up stuck in an “Invalid Input” loop! Not sure why this is, the output of that string is directly followed by an input request, which it for some reason is skipping. Hopefully I’ll learn something in the future that explains why.


After spending a lot of time on this, I have something pretty functional with a couple outstanding bugs.
The thing I noticed with the curriculum is that headers were mentioned briefly but not really talked about too much, so my program is all in one file. I may change this later after I learn more about header files. My implementation looked a lot different than the solution, but it still works. If anybody would like to review it and offer some advice, here is a link: Tic Tac Toe

Here mine!
Got the feeling it can been improved, but it works!


This is mine…
All in one file :smiley:



I was going through the solution provided by Codeacademy and I had a doubt about a part of the code:

In the function definition part, there is a line of code under void set_position() function that I did not understand. I am copy-pasting the entire section for context:

void set_position() {

std::cout << "Player " << player << "'s Turn (Enter 1-9): ";

while (!(std::cin >> position)) {

std::cout << "Player " << player << ", please enter a valid number between 1 and 9: ";


Can someone please explain what the while(!(std::cin>>position) means? how does this line of code imply that the player has not entered a valid number?

1 Like

your solution is quite elegant, thanks for sharing.

This is something new! Good job!

Im not expert but this looks like while hes entering nothing it keeps std::cout << "Player " << player << ", please enter a valid number between 1 and 9: "; using this line, havent seen declarations so not sure