- 1

Element Move (C++)

Implement the initialize function: Initialize the array with dashes '-' place 'A' on the eleventh element (index 10) Implement the moveElement function: If movement is positive, move the character 'A' to the right equivalent to the value of movement. If movement is negative, move the character 'A' to the left instead. Use the code the below // DO NOT EDIT THIS PORTION #include <iostream> using namespace std; void initialize(char e[21]); void moveElement(char e[21], int movement); void displayElements(char e[21]); int main() { char elements[21]; int movement=-1; initialize(elements); displayElements(elements); do { cin >> movement; moveElement(elements, movement); displayElements(elements); } while (movement != 0); return 0; } void displayElements(char e[21]) { for (int i=0; i<21; i++) cout << e[i]; cout << endl; } // PLACE YOUR CODE UNDER THIS COMMENT

9th Oct 2022, 3:53 AM
Ferdinand John
Ferdinand John - avatar
4 ответов
+ 1
Ferdinand John Put the whole code in Code Playground and add a link to it in the question description. Also in the question description, explain your difficulties.
9th Oct 2022, 5:51 AM
Emerson Prado
Emerson Prado - avatar
+ 1
you just copied displayElements() to move and initialize, question says: Initialize the array with dashes '-' Place 'A' on eleventh element where did you do that ? same for move...
9th Oct 2022, 5:51 AM
Tina
Tina - avatar
0
void moveElement(char e[21], int movement) { for (int i=0; i<21; i++) cout << e[i]; cout << endl; } void initialize(char e[21]) { for (int i=0; i<21; i++) cout << e[i]; cout << endl; } I've written this under the comment line. Yet, when I run the program it gives random garbage
9th Oct 2022, 5:10 AM
Ferdinand John
Ferdinand John - avatar
0
This is the link to code playground, I've done several tests, yet. I still didn't get the answer. https://www.sololearn.com/compiler-playground/ceA187no57KP
9th Oct 2022, 6:16 AM
Ferdinand John
Ferdinand John - avatar