arrays program

Write and test a function that will determine whether the values in an array are in ascending order (adjacent values are increasing or equal in value) or descending order (adjacent values are decreasing or equal in value). The function value should be 1 if the array values are in ascending order, -1 if they are in descending order and 0 if they are in neither order. Assume that the function prototype is

int order(int x[ ], int npts)

i need to let the user enter the values in the array. Andalsol let the user enter the amount of values.

so far i got the outline, but not sure how i can make the user enter the values inside the array.

// A function that will determine whether the
// values in an array are in ascending order,
// descending order or neither.
//

#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <math.h>

int value = 0
int main()
{
// Define constant, variables.
int order(int x[ ], int npts);
int npts;

// Input the number of data values.
cout << "Enter the number of data values: ";
cin >> npts;

// Input the values of the array. <<<<<< how?
cout << "Enter the values: ";









return EXIT_SUCCESS;
}
//-------------------------------

int order(int x[], int npts)
{




return value;
}
//--------------------------



any info would help me... thanks
Assuming you are using a decent compiler, after reading in "npts" from the user, declare an array as such:

 
int array[ npts ];


And then use cin to read into each element in the array.
eg,

 
cin >> array[ 0 ]; // ... 


but you'll need a more generalized loop...
I think that dinamic allocation would be better...
1
2
3
int npts, *array;//declarations
cin >> npts;//get array size
array = new int [npts]; // set array size 
Topic archived. No new replies allowed.