ARTICLE AD BOX
Below is the code and results. Some commented out lines use when testing to insure mapping and updating array was working.
#include <map> #include <iostream> using namespace std; int main() { int user_input; // create board positions string board_array[3][3] = {{"1","2","3"}, {"4","5","6"}, {"7","8","9"}}; map<int, string> mapped_square = {{1, board_array[0][0]},{2, board_array[0][1]}}; cout << "What square do you choose? "; cin >> user_input; mapped_square[user_input] = "x"; //cout << mapped_square[user_input] << endl; //board_array [0][0] = "x"; // Display board cout << "+-----------------+" << endl << "| " << board_array[0][0] << " | " << board_array[0][1] << " | " << board_array[0][2] << " |" << endl << "|-----------------|" << endl << "| " << board_array[1][0] << " | " << board_array[1][1] << " | " << board_array[1][2] << " |" << endl << "|-----------------|" << endl << "| " << board_array[2][0] << " | " << board_array[2][1] << " | " << board_array[2][2] << " |" << endl << "+-----------------+" << endl; return 0; }Result:
What square do you choose?1 +-----------------+ | 1 | 2 | 3 | |-----------------| | 4 | 5 | 6 | |-----------------| | 7 | 8 | 9 | +-----------------+ Process finished with exit code 0124k31 gold badges280 silver badges489 bronze badges
2
