Advertisement
rozman50

vaja_7

Nov 27th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int n, m;
  9. cout << "Vpisi velikost polja med 5 in 20 " << endl;
  10. while (true) {
  11. cin >> n;
  12. cin >> m;
  13.  
  14. if ((n >= 5 && n <= 20) && (m >= 5 && m <= 20)) {
  15. break;
  16. }
  17. else {
  18. cout << "Vpisi ponovno " << endl;
  19. }
  20. }
  21.  
  22.  
  23. // inicializacija 2D polja
  24. char** polje;
  25. polje = new char*[m];
  26. for (int i = 0; i < m; i++)
  27. polje[i] = new char[n];
  28.  
  29. for (int i = 0; i < n; i++) {
  30. for(int j = 0; j < m; j++) {
  31. polje[i][j] = '*';
  32. }
  33. }
  34.  
  35. bool turn = true;
  36. char znak = 'X';
  37. int coN, coM;
  38. while (true) {
  39.  
  40.  
  41. cout << "Vnesi koordinato n (od " << 0 << " do " << n << "): ";
  42. cin >> coN;
  43. cout << "Vnesi koordinato m (od " << 0 << " do " << m << "): ";
  44. cin >> coM;
  45.  
  46. if (polje[coN][coM] == '*') {
  47. polje[coN][coM] = znak;
  48.  
  49. for (int i = 0; i < n; i++) {
  50. for (int j = 0; j < m; j++) {
  51. cout << polje[i][j] << " ";
  52. }
  53. cout << endl;
  54. }
  55. turn = !turn;
  56. if (turn) znak = 'X';
  57. else znak = 'O';
  58. }
  59. else {
  60. cout << "Vnesena koordinata je že zasedena!" << endl;
  61. }
  62.  
  63.  
  64. }
  65.  
  66.  
  67.  
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement