CPP   28

array-boxes2.cpp

Guest on 14th January 2022 10:29:27 AM

  1. #include <iostream> using namespace std; void displayGrid(char a[][3]) {
  2. // Row for(int row=0;row<3;row++) {
  3. // Column for(int column=0;column<3;
  4. column++) { cout << a[row][column]; }
  5.  // Go to the next line. cout << endl; } } void clearGrid(char a[][3]) {
  6.  // Row for(int row=0;row<3;row++) {
  7.  // Column for(int column=0;column<3;column++) { a[row][column]='.'; } } } void setGrid(char a[][3]) { int row; int column;
  8.  char symbol; cout << "What symbol do you want to store: "; cin >> symbol; cout << "Enter in a row from 1 to 3 : "; cin >> row; cout << "Enter in a column from 1 to 3 : "; cin >> column;
  9.  // Adjust values. row--; column--; // Only if valid locations, assign a star. if(row>=0 && row<=2 && column>=0 && column<=2) { a[row][column]=symbol; } else cout << "Invalid location!" << endl; } int main() { char grid[3][3]; clearGrid(grid); //grid[0]={'X','X','X'}; displayGrid(grid); setGrid(grid); setGrid(grid);
  10. displayGrid(grid); return 0; }

Raw Paste


Login or Register to edit or fork this paste. It's free.