aboutsummaryrefslogtreecommitdiff
path: root/week06/ex3.cpp
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2023-12-03 13:33:32 +0200
committerSyndamia <kamen@syndamia.com>2023-12-03 13:33:32 +0200
commit0996e05988b5d38faba0f616f06e6dcc7466930e (patch)
tree5efa650f38dddfaf0a1389a2cb2f4075bb76e8d8 /week06/ex3.cpp
parentebccf5fed44edd6f0971852701708259e855cd17 (diff)
downloadupp-2023-solutions-0996e05988b5d38faba0f616f06e6dcc7466930e.tar
upp-2023-solutions-0996e05988b5d38faba0f616f06e6dcc7466930e.tar.gz
upp-2023-solutions-0996e05988b5d38faba0f616f06e6dcc7466930e.zip
[w6] Added solutions for ex1 and ex2 with partials for ex3 and 4
Diffstat (limited to 'week06/ex3.cpp')
-rw-r--r--week06/ex3.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/week06/ex3.cpp b/week06/ex3.cpp
new file mode 100644
index 0000000..a37bbb0
--- /dev/null
+++ b/week06/ex3.cpp
@@ -0,0 +1,50 @@
+#include <iostream>
+
+void putOn(char board[3][3], char marker, size_t position) {
+ position--;
+ board[position / 3][position % 3] = marker;
+}
+
+void print(char board[3][3]) {
+ for (size_t row = 0; row < 3; row++) {
+ for (size_t col = 0; col < 3; col++) {
+ std::cout << board[row][col];
+ }
+ std::cout << std::endl;
+ }
+}
+
+unsigned win(char board[3][3]) {
+ bool notFull = false;
+ char start = ' ';
+ bool won = false;
+
+ /* Проверяваме редовете */
+ for (size_t row = 0; row < 3; row++) {
+ start = board[row][0];
+
+ }
+}
+
+
+
+int main() {
+ char board[3][3] = { { ' ' } };
+ bool playerOneTurn = true;
+
+ size_t position;
+ unsigned winStatus = 0;
+ do {
+ std::cin >> position;
+ if (playerOneTurn) {
+ putOn(board, 'X', position);
+ }
+ else {
+ putOn(board, 'O', position);
+ }
+ playerOneTurn = !playerOneTurn;
+
+ print(board);
+ winStatus = win(board);
+ } while (winStatus == 0);
+}