### Manipulating Array Elements

Currently, I'm writing a program that's designed to make a user try and take a printed array of elements, randomly chosen from the values of 1 to 9 and reverse them to get them in order from 1 to 9. (However, they cannot simply pick which printed element to switch with which, they must pick how many elements in total they wish to reverse. (Example: If the array is printed 1, 2, 3, 4, 5, 6, 7, 8, 9 and the user enters 4, the printed array would become 4, 3, 2, 1, 5, 6, 7, 8, 9))

Sorry if it's not really clear what I'm trying to do. It's a difficult concept to explain. Anyway, I've got almost everything working. Right now I'm trying to copy the printed array (Called ReverseArray) into a second, temporary array (ReverseArrayTemp) to perform the reversal and then overwrite ReverseArray with ReverseArrayTemp.

 ``1234567891011121314151617`` `````` // Complex array loop. Outer for loop copies the ReverseArray to ReverseArrayTemp in alternating order (Starting from highest element in ReverseArray and the lowest in ReverseArrayTemp). // So 9 becomes 1, 8 becomes 2, etc. After each element swap, ReverseArray element increments, and ReverseArrayTemp decrements. for ( ReverseArray[ i ] = ReverseArrayTemp[ index ]; getInteger() < 8; ++i, --index ) { // ReverseArrayTemp [ index ] = getInteger( 1, 9 ); do { for ( ReverseArrayTemp[ index2 ] = 0; index2 < 9; ++index2 ) { if() ; } } while( ReverseArrayTemp[ index ] > 0 ); } }``````

Everything else is working fine, I'm just stumped on how I'm supposed to word this and lay it out in coding. Any help?
Last edited on
 ``1234`` ``````//toReverse stores number of elements to reverse --toReverse; for(int i = 0; i < (toReverse / 2); ++i) std::swap(ReverseArray[i], ReverseArray[toReverse - i]);``````
Sorry MiiNiPaa, not sure I'm on the same page with you. Are you suggesting I replace my entire double for loop with that or just one of them?
Both. Before that snippet array is normal. Arter it is reversed.
Thank you, much appreciated.
Topic archived. No new replies allowed.