//*****************************************************************
// R. A. Hillyard
// reverse.cpp
// March 2001
//
//  Get up to MAXVAL doubles from the user (sentinel = 0.0).
//  Store them in an array and then print them in reverse order.
//*****************************************************************

#include <iostream>

using namespace std;

const int MAXVAL = 20;

int main()
  {
  int numVals;             //counter for number of entries read
  double value[MAXVAL];    //declare the array of doubles

  //Print user message
  cout << "Enter up to " << MAXVAL << " doubles (one per line)\n";
  cout << "Type 0.0 to terminate\n";
  
  //get input from user
  for(numVals = 0; numVals < MAXVAL; numVals++)
    {
    cin >> value[numVals];     //input value to array element
    if(value[numVals] == 0.0)  //if end of data
      break;
    }//endfor
  //Note that numVals now contains the actual # of entries and (0 <= numVals <= MAXVAL)

  cout << "\nreverse order:\n";
  for(int i = numVals - 1; i >= 0; i--)
    cout << value[i] << endl;

  return 0;
  }
//*****************************************************************
//**********************Program Output*****************************
Enter up to 20 doubles (one per line)
Type 0 to terminate
34.7
15
5.8
0.34
33.5
17.34
65.45
1234.45
0.0

reverse order:
1234.45
65.45
17.34
33.5
0.34
5.8
15
34.7