Ascending Arrays

Ok so I have built an array program but I can't seem to figure out how to test the array so that it make the array in ascending order. Ideas?

#include<iostream>

using namespace std;

void Input_Row ( double array[1][3], int ROWS, int COLUMNS)
{
int a;
for (int i = 0 ; i <= ROWS; i++)
for (int j = 0 ; j <= COLUMNS; j++)
{
cout<< " Enter the first expression for row " << i+1 << " Column " << j+1 <<" ";
cin >> a;
cout<< endl;
if ( 1> a || a > 200 )
{
cout << "Error this value is not in the correct range. Choose a value between 1 and 200"<< endl ;
cin >> a;
}


array[i][j] = a;
}
}


void Read_Row (double array [1][3], int ROWS, int COLUMNS)
{
for (int i = 0 ; i <= ROWS; i++)
{
for (int j = 0 ; j <= COLUMNS; j++)
{
cout << array[i][j] << " " ;
}
cout<< endl;
}
}


int main ()
{
const int ROWS=1 ;
const int COLUMNS=3;
double array [ROWS][COLUMNS];
Input_Row (array, ROWS, COLUMNS);
READ_ROW (array, ROWS, COLUMNS);

}
To test if a sequence is in ascending order, iterate through the elements of the sequence. As you go through the sequence, if any element is smaller than the element just before it, the sequence is not in ascending order. Conversely, if you reach the end of the sequence without encountering such an element, the sequence is in ascending order.
What JLBorges said, or do you want the program to rearrange the array so that they are ascending if they aren't already?
In order to rearrange the array yoy can use a lot of method. The simplest being bubble sort. You can check the web for this. It's natural to consider your array unsorted as there is no guarantee for the opposite.

Some other issues in your code:

1) You are using int a; to store an element of a double array, won't work as expected

2) READ_ROW (array, ROWS, COLUMNS); You have never declared this function. C++ is case sensitive.

3) if ( 1> a || a > 200 ) use a loop in order to keep asking for correct input (not just once).
Topic archived. No new replies allowed.