-
c++ question
:confused:
hi ,
im new to c++ , i just did a programme that figures out whether or not the values stored in an array of ints are stored in descending order.could any body check this out because it giving me descending 2 times..
#include<iostream.h>
//**************************************
const int MAX = 10;
typedef int LIST_ST[MAX];
//**************************************
void array_des(int array[],int num,int& found);
//**************************************void main()
{
LIST_ST array;
int found ,
num;
array_des(array, num , found);
}
//**************************************
void array_des(int array[] , int num , int& found)
{
int ct;
cout<<"how many numbers :";
cin >> num;
cout << "enter numbers";
for(ct = 0 ; ct < num ;++ct)
cin >>array[ct];
for(ct = 0 ;ct <= num ;++ ct)
if(array[ct] >= array[ct+1])
cout <<"decsending";
found = 1;
}
-
Try this.
Code:
void array_des(int array[] , int &num , int& descending)
{
int ct;
cout<<"how many numbers :";
cin >> num;
cout << "enter numbers";
for (ct = 0 ; ct < num ; ++ct)
cin >>array[ct];
descending = 1;
for (ct = 0 ;ct < num-1 ; ++ct)
{
if (array[ct] < array[ct+1])
descending = 0;
}
if (descending)
cout <<"descending" << endl;
}