pointers and arrays

Is there a way to make the "enter value #0" and "Value #0" just start at 1 instead of 0?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 #include <iostream>
using namespace 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 = new float[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;
}
and on the reversed set, why does it start at 0 instead of the highest i?
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.
Topic archived. No new replies allowed.