c++ question

This is a discussion on c++ question within the C++ Programming forums, part of the General Programming Boards category; hi , im new to c++ , i just did a programme that figures out whether or not the values ...

  1. #1
    san
    san is offline
    Registered User
    Join Date
    Jul 2002
    Posts
    13

    Question c++ question




    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;
    }

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    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; 
    }
    Last edited by swoopy; 07-09-2002 at 08:33 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 03:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 01:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21