fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. void draw_grid()
  9. {
  10.  
  11. char grid[9][9] = { {'x','x','x','x','x','x','x','x','x'},
  12. {'x','x','x','x','x','x','x','x','x'},
  13. {'x','x','x','x','x','x','x','x','x'},
  14. {'x','x','x','x','x','x','x','x','x'},
  15. {'x','x','x','x','x','x','x','x','x'},
  16. {'x','x','x','x','x','x','x','x','x'},
  17. {'x','x','x','x','x','x','x','x','x'},
  18. {'x','x','x','x','x','x','x','x','x'},
  19. {'x','x','x','x','x','x','x','x','x'}};
  20. char character = '*';
  21. char quest = 'Q';
  22.  
  23. int position[2] = {4,4};
  24. int quest_position[2];
  25.  
  26. srand(time(NULL));
  27.  
  28. quest_position[0] = rand() % 9 + 0;
  29. quest_position[1] = rand() % 9 + 0;
  30.  
  31. char direction;
  32.  
  33. for(int i = 0; i < 9; i++){
  34. for (int j = 0; j < 9; j++){
  35. if(i == position[0] && j == position[1])
  36. cout << character;
  37. if(i == quest_position[0] && j == quest_position[1])
  38. cout << quest;
  39. else
  40. cout << grid[i][j];
  41. cout << " ";
  42. }
  43. cout << endl;
  44. }
  45. }
  46.  
  47. int main()
  48. {
  49. draw_grid();
  50. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
x x x x x x x x x 
x x x x x x x x x 
x x x x x x x x x 
x x x x x x x x x 
x x x x *x x x x x 
x x x x x x x x x 
x x x x x x x x x 
x Q x x x x x x x 
x x x x x x x x x