Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 11.03.2020.cpp:
- //
- #include <iostream>
- using namespace std;
- int main()
- {
- //creating array
- char myArray[3][3];
- for (int x = 0; x < 3; x++)
- {
- for (int y = 0; y < 3; y++)
- {
- myArray[x][y] = ' ';
- }
- }
- bool isWin = false;
- while (!isWin)
- {
- enter_coordinates:
- cout << "Please enter X:" << endl;
- int userX = 0;
- cin >> userX;
- cout << "Please enter Y:" << endl;
- int userY = 0;
- cin >> userY;
- if (!(userX < 3) && (userX < 0))
- {
- cout << "Wrong coordinates!" << endl;
- goto enter_coordinates;
- }
- if (!(userY < 3) && (userY < 0))
- {
- cout << "Wrong coordinates!" << endl;
- goto enter_coordinates;
- }
- if (myArray[userX][userY] != ' ')
- {
- cout << "There is " << myArray[userX][userY] << " already in this point" << endl;
- goto enter_coordinates;
- }
- else if (myArray[userX][userY] == ' ')
- {
- myArray[userX][userY] = 'X';
- }
- //---
- cout << endl;
- for (int y = 0; y < 3; y++)
- {
- for (int x = 0; x < 3; x++)
- {
- char outChar = myArray[x][y];
- if (outChar == ' ')
- {
- outChar = '_';
- }
- cout << outChar << ' ';
- }
- cout << endl;
- }
- if (myArray[0][0] == 'X' && myArray[1][0] == 'X' && myArray[2][0] == 'X')isWin = true;//1
- if (myArray[0][0] == 'X' && myArray[0][1] == 'X' && myArray[0][2] == 'X')isWin = true;
- if (myArray[0][1] == 'X' && myArray[1][1] == 'X' && myArray[2][1] == 'X')isWin = true;
- if (myArray[0][2] == 'X' && myArray[1][2] == 'X' && myArray[2][2] == 'X')isWin = true;
- if (myArray[1][0] == 'X' && myArray[1][1] == 'X' && myArray[1][2] == 'X')isWin = true;
- if (myArray[2][0] == 'X' && myArray[2][1] == 'X' && myArray[2][2] == 'X')isWin = true;
- if (myArray[0][2] == 'X' && myArray[1][1] == 'X' && myArray[2][0] == 'X')isWin = true;
- if (myArray[0][0] == 'X' && myArray[1][1] == 'X' && myArray[2][2] == 'X')isWin = true;
- }
- }
Add Comment
Please, Sign In to add comment