Trying to reverse elements in array by using a temporary variable. I can't figure out how to do it
int arraysize = 12;//Size of the array
int option;// Option to be switched
int list[12];//numbers in the array
int total = 0;// Total of all numbers initialised to zero
double average = 0;// average of all numbers
int largestNum = 0;//largest Number
int smallestNum = 6;//first number in the array
int NumberOccurance = 0;// number of times the checked number appears
int usernum;//number to be check for times it appears
int userscaleup;//number to be multiplied by the array contents
int tempnum;// store the value
int endarray;
ifstream infile("data.dat");
ofstream outfile("output.dat");
do
{
cout << "\t7. Reverse Order\n";
cin >> option;// Taking in the users option from the menu
switch (option)
case 7:
case 7:
for (int index = 0; index < arraysize/2; index++, endarray--)
{
infile >> list[index];
int endarray = list[arraysize];// variable endarray holds value of end side of array
int swapholder = list[index];
list[index] = list[endarray];//Swap
list[endarray] = swapholder;
cout << list[index] << ' ';
}
break;
while (option != 9);
}
I keep getting output of random negative numbers. Tried multiple solutions. The line I've commented out is also giving random negative numbers.
The arraysize is 12.
have to do this using a temp variable. Could someone please show me the correct method to do this?
Edit: Updated my code. The program is now building but it's crashing when I run it. Any suggestions?
This is pseudo code, but should give you an idea. Here I use two counters that move towards the middle from the front and back of the array