#include <iostream>
usingnamespace std;
void reverse_array(float array[], int arraylength) // makes the order go in reverse
{
for (int i = 0; i < (arraylength / 2); i++)
{
float temporary = array[i];
array[i] = array[(arraylength - 1) - i];
array[(arraylength - 1) - i] = temporary;
}
}
int main()
{
int arraylength;
cout << "Enter how many values you have: ";
cin >> arraylength; // has to be unlimited because the user types in the amout of space needed
float* array = newfloat[arraylength];
cout << "Enter the values:" << endl; // not sure how to start at #1 instead of #0 where it starts
for (int i = 0; i < arraylength; i++)
{
cout << "Enter value #" << i << " = ";
cin >> array[i];
}
reverse_array(array, arraylength); // brings it to the void statement
cout << "The new order in reverse is " << endl;
for (int i = 0; i < arraylength; i++) // issue here and cant figure it out, the values are in the reverse order but the array # is not
{
cout << "Value #" << i << " = " << array[i] << endl;
}
delete[] array; // closes it to save memory
system("pause"); // if this isnt here the program closes after the last number has been entered
return 0;
}
Just print (i + 1) in the cout statement instead of i.
the values are in the reverse order but the array # is not
Think about it. If the indices were "reversed" that can only mean that you are looping through them backwards (since indices are not stored anywhere; they are just offsets into the data). If you loop through an array backwards then of course you're going to print it in reverse order, but the array itself is not in reverse order. You need to actually move the data around to truly reverse it, like your reverse_array function does.