For whatever reason, I had to declare int I before the for loop due to some error code, however when I try to run this, I am only getting the first numbers switched in each array. I have to switch a total of 2 arrays, A and B switch, and array C is reversed. Not sure why this is happening.
int I;
for (int I; I < 7; I++)
{
temp1 = Array_A[I];
Array_A[I] = Array_B[I];
Array_B[I] = temp1;
}
cout << "Array A is: " << Array_A[I] << " " << "Array B is: " << Array_B[I] << endl;
You need to set the initial value of I: for (int I=0; I < 7; I++)
Note that this variable I only exists inside the loop. That brings us to your next problem, the last line is OUTSIDE the loop, and that's why you had to declare int I at the beginning of the program. Note that this is a completely different variable from the one inside of the for loop.
I think you want to print the full contents of the arrays, which means you'll want another loop to do it.
I actually forgot about the I = 0 for the post. I am trying to swap a 7 value array with another 7 value array, however when I try this, it only prints out the first number from each array. Should I change the for loop to a while loop or just copy the
cout << "Array A is: " << Array_A[I] << " " << "Array B is: " << Array_B[I] << endl;