array question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thebrainmore
    New Member
    • Oct 2006
    • 5

    array question

    I'm trying to find the lowest number in the array but cant seem to finish the function in the main...could some help please


    Code:
    #include<iostream>
    
    int FindLowNum(int [], int );
    
    
    int main()
    {
    
           const int arraySize = 20;
    
           int a[ arraySize ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
    
          int total = 0;
    
          // sum contents of array a
          for ( int i = 0; i < arraySize; i++ )
              total += a[ i ];
    
           cout << "Total of array element values is " << total << endl;
    
    
            int FindLowNum(int a, int size);
    
           cout << "the lowest value is :\n"<< a;
    
    
           return 0;  // indicates successful termination
    
    }
    
    int FindLowNum(int array[], int size)
    {
      int lowest_so_far = array[0];
      for (int i=1; i<size; i++)
      {
        if (array[i]<lowest_so_far)
          lowest_so_far = array[i];
      }
      return lowest_so_far;
    
    }
  • ltgbau
    New Member
    • Sep 2006
    • 41

    #2
    see two bold command lines

    Code:
    #include<iostream>
    
    int FindLowNum(int [], int );
    
    
    int main()
    {
    
           const int arraySize = 20;
    
           int a[ arraySize ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
    
          int total = 0;
    
          // sum contents of array a
          for ( int i = 0; i < arraySize; i++ )
              total += a[ i ];
    
           cout << "Total of array element values is " << total << endl;
    
    
          [B]  int n = FindLowNum(a, arraySize);
    
           cout << "the lowest value is :\n"<< n;[/B]
    
    
           return 0;  // indicates successful termination
    
    }
    
    int FindLowNum(int array[], int size)
    {
      int lowest_so_far = array[0];
      for (int i=1; i<size; i++)
      {
        if (array[i]<lowest_so_far)
          lowest_so_far = array[i];
      }
      return lowest_so_far;
    
    }

    Comment

    • analwarsi
      New Member
      • Oct 2006
      • 7

      #3
      See the highlighted line
      Code:
      #include<iostream>
      
      int FindLowNum(int [], int );
      
      
      int main()
      {
      
             const int arraySize = 20;
      
             int a[ arraySize ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
      
            int total = 0;
      
            // sum contents of array a
            for ( int i = 0; i < arraySize; i++ )
                total += a[ i ];
      
             cout << "Total of array element values is " << total << endl;
      
      [B]
      cout << "the lowest value is :\n"<<FindLowNum(a, arraySize)[/B];
      
      
             return 0;  // indicates successful termination
      
      }
      
      int FindLowNum(int array[], int size)
      {
        int lowest_so_far = array[0];
        for (int i=1; i<size; i++)
        {
          if (array[i]<lowest_so_far)
            lowest_so_far = array[i];
        }
        return lowest_so_far;
      
      }

      Comment

      • thebrainmore
        New Member
        • Oct 2006
        • 5

        #4
        thank you, worked perfectly

        Comment

        Working...