#include <iostream>
#include <new>
using namespace std;

int main ()
{
  int i,n;
  int * p;
  cout << "How many numbers would you like to type? ";
  cin >> i;
  p= new (nothrow) int[i];
  if (p == 0)
    cout << "Error: memory could not be allocated";
  else
  {
    for (n=0; n<i; n++)
    {
      cout << "Enter number: ";
      cin >> p[n];
    }
    cout << "You have entered: ";
    for (n=0; n<i; n++)
      cout << p[n] << ", ";
    delete[] p;
  }
  return 0;

for example i want 3 numbers, say the numbers you enter are 1,2,3, it'l will come up ive entered 1,2,3 in that order. i want to know how you reverse that so that it reads what you've typed in,(dynamic memory etc.) then reverses that order. tried about with it but cant get it going? any takers?

Either you insert the numbers in the array in reverse order and print the array normally

 for (n=i-1; n!=-1; n--)
    {
      cout << "Enter number: ";
      cin >> p[n];
    }

or normally insert items in the array, and print them in reverse order

for (n=i-1; n!=-1; n--)
      cout << p[n] << ", ";

Edited 4 Years Ago by Lucaci Andrew

did that second method there and its working si far except for one instance, when i do 1,2,3 it comes up 0,3,2,1?

Yeah, well initially was

 for (n=i; n!=-1; n--)

but I edited in

 for (n=i-1; n!=-1; n--)

Was a little bit quick on typewriting, forgot that -1 near the i. Try it now, it will definately work.

lifesaver lucaci, as you can probably tell, im a beginner,trying to learn all the time.lol
Thanks again

Glad I could help. Also, don't forget to mark this thread as solved, since the matter at hand is no longer the problem. If you do have further questions, for each question start a new thread explaining the situation.

This article has been dead for over six months. Start a new discussion instead.