#include "stdafx.h" #include <iostream> #include <random> #include <time.h> #include <conio.h> #include <locale> using namespace std; char name1[30]; char name2[30]; char table[3][3]; bool step; void instructions() { cout << "\t\t***Хрестики-нолики***\n\n"; cout << "Правила\n"; cout << "Грають два гравцi на полі 3х3\n"; cout << "Виграє той хто складе виграшну комбiнацiю\n"; cout << "Вигляд поля\n\n"; int l = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << " | " << l + 1 << ' '; table[i][j] = char(49 + l); l++; } cout << " | "; cout << endl; } cout << "\nДля ходу нажмiть номер клiтинки поля\n"; cout << "Для того щоб почати гру введiть будь-яку клавiшу"; _getch(); } bool input() { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << " | " << table[i][j] << ' '; } cout << " | "; cout << endl; } cout << endl; if (step) { cout << "Ходить " << name1 << " : " << endl; } else { cout << "Ходить " << name2 << " : " << endl; } int n; cin >> n; if (n < 1 || n > 9) { return false; } int i, j; if (n % 3 == 0) { j = n % 3 - 1; i = n / 3; } if (table[i][j] == 'o' || table[i][j] == 'x') { return false; } if (step) { table[i][j] = 'x'; step = false; } else { table[i][j] = 'o'; step = true; } return true; } bool win() { for (int i = 0; i < 3; i++) if ((table[i][0] == table[i][1]) && (table[i][0] == table[i][2])) return true; else if ((table[0][i] == table[1][i]) && (table[0][i] == table[2][i])) return true; else if ((table[0][0] == table[1][1]) && (table[0][0] == table[2][2]) || (table[0][2] == table[1][1]) && (table[0][2] == table[2][0])) return true; return false; } int main() { setlocale(LC_ALL, "rus"); instructions(); system("cls"); int i = 0; cout << "Введiть iм'я першого гравця" << endl; cin.getline(name1, 30); cout << "Введiть iм'я другого гравця" << endl; cin.getline(name2, 30); srand(time(NULL)); if (rand() & 1) { step = true; } else { step = false; } while (!win()) { if (i == 9) { cout << "Нiчия!"; _getch(); return -1; } system("cls"); if (!input()) { cout << "Ви ввели невiрнi дані повторіть" << endl; _getch(); } i++; } system("cls"); if (step) { cout << "Виграв: " << name2 << endl; } else { cout << "Виграв: " << name1 << endl; } _getch(); return 0; } 

I can not find a mistake.

Closed due to the fact that participants Igor , Anton Shchyrov , αλεχολυτ , aleksandr barakin , D-side 10 Nov '16 at 12:15 are off topic.

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Igor, Anton Shchyrov, αλεχολυτ, D-side
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    "I can not find an error" - even under the debugger you do not see on which line it falls? - PinkTux

2 answers 2

 int i, j; /* а если n % 3 != 0 ? */ if (n % 3 == 0) { j = n % 3 - 1; i = n / 3; } /* то здесь переменные j и i не инициализированы */ if( table[i][j] == 'o' || table[i][j] == 'x' ) { 

PS Learn to use different tools, not just the "build project" button. Even the simplest debugger can save you a lot of time:

enter image description here

  • but how to fix, I can not understand - toshka-pitoshka
  • all nashol, thanks - toshka-pitoshka

Instead of this

if (n % 3 == 0) { j = n % 3 - 1; i = n / 3; }

Must be

 i = n / 3; j = n % 3;