help with arrays

I am having trouble understanding arrays. What I need help with is Create an array of type double that can hold up to 5 elements. Ask the user for 5 numbers. Display those numbers in the reverse order from which they were entered. Any help would be greatly appreciated.

code

#include <iostream>

using namespace std;

int main() {
double numbers[5];
numbers[0] = 55;
numbers[1] = 60;
numbers[2] = 65;
numbers[3] = 70;
numbers[4] = 75;

for (int i=0; i < 5; i++) {
cout << "Enter number: ";
cin >> numbers[i];
}

system("pause");
return 0;
}
Last edited on
Please use code tags. http://www.cplusplus.com/articles/jEywvCM9/
You can edit your post, highlight your code and click the <> button on the right.

1
2
3
4
5
numbers[0] = 55;
numbers[1] = 60;
numbers[2] = 65;
numbers[3] = 70;
numbers[4] = 75;

What are you trying to do here? Initialise the array? If you wanted to initialise the array, which I would recommend that you do, you can do this: double numbers[5] = { 0 }; // zero initialise array

Display those numbers in the reverse order from which they were entered.

How would you display them in forward order?
Apply that logic to display them in reverse.
Hint: the last element is at index 4, second last is at 3, third last is at 2, etc...
I'm not quiet sure. I was following the example giving by my instructor. I am just trying to get the user to enter in 5 numbers. then use a for loop to display those 5 numbers entered in reverse.
Last edited on
so i wouldn't need to include the part I listed before with
numbers[0]
numbers[1]
numbers[2]
numbers[3]
numbers[4]

so i'm not sure about how to do a for statement for the reverse order of what is entered by the user

#include <iostream>

using namespace std;

int main() {
double numbers[5];

for (int i=0; i < 5; i++) {
cout << "Enter number: ";
cin >> numbers[i];
}

system("pause");
return 0;
}
Topic archived. No new replies allowed.