DEV Community

Discussion on: Tic Tac Toe C++

Collapse
 
elvisoric profile image
Elvis Oric

For the next post, use this code as starting point and refactor it.
There is a lot of repetition.
You can focus on:

  • Do you really need switch to track player's turn?
  • Look at this pattern that can be found in each case:
{
if (arr[0][0] == 'X' || arr[0][0] == '#') {
     cout << "Enter another number";
     cout << "Enter the number\n";
     cin >> number;
     wrong = true;
} else {
arr[0][0] = 'X';
}
break;
}
Enter fullscreen mode Exit fullscreen mode
  • How can you improve tihs? Can you move this in a function? Can you find some kind of correlation between input and a and b from arr[a][b]
  • Try to make code more readable for other programmers.

Good luck.
If you need any advice, feel free to contact me.

Collapse
 
bilalmohib profile image
Muhammad Bilal Mohib-ul-Nabi • Edited

Hi Elvis Thanks for your reply.Your suggestion is much appreciated.Thank you.I will definately consider your suggestions.
Regards
Muhammad Bilal