Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- using namespace std;
- int main()
- {
- int n, m;
- cout << "Vpisi velikost polja med 5 in 20 " << endl;
- while (true) {
- cin >> n;
- cin >> m;
- if ((n >= 5 && n <= 20) && (m >= 5 && m <= 20)) {
- break;
- }
- else {
- cout << "Vpisi ponovno " << endl;
- }
- }
- // inicializacija 2D polja
- char** polje;
- polje = new char*[m];
- for (int i = 0; i < m; i++)
- polje[i] = new char[n];
- for (int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- polje[i][j] = '*';
- }
- }
- bool turn = true;
- char znak = 'X';
- int coN, coM;
- while (true) {
- cout << "Vnesi koordinato n (od " << 0 << " do " << n << "): ";
- cin >> coN;
- cout << "Vnesi koordinato m (od " << 0 << " do " << m << "): ";
- cin >> coM;
- if (polje[coN][coM] == '*') {
- polje[coN][coM] = znak;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- cout << polje[i][j] << " ";
- }
- cout << endl;
- }
- turn = !turn;
- if (turn) znak = 'X';
- else znak = 'O';
- }
- else {
- cout << "Vnesena koordinata je že zasedena!" << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement