How to keep an element in my array? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to keep an element in my array?

I have a c++ code but I'm having a problem. I need to insert a value on my array [][] and then I print it. However I need to keep and show that value after that and insert another one. How can I do this ?

22nd Jan 2018, 5:08 AM
María José
María José - avatar
9 Answers
+ 5
I don't really understand your question so I'm going to give an example of my best guess. int s, a[] = {9, 5, 1, 0, 4, 2, 8, 6, 3, 7}; s = a[6]; // gets 8 a[6] = 10; cout << s << a[6]; // outputs 8 & 10 If this isn't what you're asking, please give an example such as this one describing my code above: put 9, 5, 1, 0, 4, 2, 8, 6, 3, 7 into an array replace the current sixth position with 10 display both the original and new values of the sixth position yielding 8 & 10
22nd Jan 2018, 5:24 AM
John Wells
John Wells - avatar
+ 5
char board[15][15] cin >> position; // row & column if (board[position.row][position.column] == ' ') { cin >> letter; // if good letter store in board[position.row][position.column] } else { cout << "space in use"
22nd Jan 2018, 5:48 AM
John Wells
John Wells - avatar
+ 3
You could do: string ARRAY[][] = {{"A","B","C"},{"D","E","F"},{"G","H","I"}}; This allocates ARRAY[3][3] with 9 values.
22nd Jan 2018, 5:37 AM
John Wells
John Wells - avatar
+ 3
so array[playerNumber][word] type deal
22nd Jan 2018, 5:41 AM
John Wells
John Wells - avatar
+ 2
Scrabble board[column][row] for the players move
22nd Jan 2018, 5:43 AM
John Wells
John Wells - avatar
+ 1
@John Wells What I mean, I'm giving the input for an string array so i give the positions ARRAY[0][0]= "A" // I insert the value that I what there all the values I need to insert them one by one for example the next one could be ARRAY [0][1] = "B" And I need to keep holding both values
22nd Jan 2018, 5:32 AM
María José
María José - avatar
+ 1
No that's not useful, It's an scrabble game actually only by compilation time I need to insert the values per player one by one in the position that they what and the values the need. thanks!
22nd Jan 2018, 5:40 AM
María José
María José - avatar
+ 1
but I still to keep on the screen every value, that's the matter that I'm having Only the last movement it's shown on the tablegame
22nd Jan 2018, 5:44 AM
María José
María José - avatar
+ 1
I'll try thank so much John
22nd Jan 2018, 5:49 AM
María José
María José - avatar