presentation questions:
- how to compile a c++ file?
- in vs code i would use the built in terminal and follow ctrl+shift+b and run the g++ command
g++ naughtsandcrosses.cpp -o naughtsandcrosses ./naughtsandcrosses
- What is this line of code doing?
- the example code
mark = (player == 1) ? 'X' : 'O';
-this operator assigns the 'X' to mark if the player is 1, otherwise the player is 2 with 'O' setting the players symbols.
- what is this function doing?
- example code
int checkwin() {
if (sqaure[1] == square[2] == sqaure[3]) return 1;} ...
this checks all possible win combinations over all directions. it also returns a 1 if a player wins, 0 for a draw and -1 to continue the game.
- how does a for loop work in c++?
- a for loop is a tool to utilise repitition that allows you to write code that can be executed a specific number of times. this could have been used to simplify the win-check in my naughts and crosses code but i used if-else chains.