Thread: arrays and functions (beginner q)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    11

    arrays and functions (beginner q)

    edit since this question is more important than my other now:

    Code:
    void mode( int freq[], int answer[], int size )
    {
       int rating, largest = 0, modeValue = 0;
    
       cout << "\n********\n  Mode\n********\n";
    
       for ( rating = 1; rating <= 9; rating++ )
          freq[ rating ] = 0;
    
       for ( int j = 0; j < size; j++ )
          ++freq[ answer[ j ] ];
    
       cout << "Response"<< setw( 11 ) << "Frequency"
            << setw( 19 ) << "Histogram\n\n" << setw( 55 )
            << "1    1    2    2\n" << setw( 56 )
            << "5    0    5    0    5\n\n";
    
       for ( rating = 1; rating <= 9; rating++ ) {
          cout << setw( 8 ) << rating << setw( 11 )
               << freq[ rating ] << "          ";
    
          if ( freq[ rating ] > largest ) {
             largest = freq[ rating ];
             modeValue = rating;
          }
    
          for ( int h = 1; h <= freq[ rating ]; h++ )
             cout << '*';
    
          cout << '\n';
       }
    
       cout << "The mode is the most frequent value.\n"
            << "For this run the mode is " << modeValue
            << " which occurred " << largest << " times." << endl;
    }

    what it basically does is display the types of responses, the frequency at which those responces occurred (it puts that data in a nice tabular format) and alongside a histogram of the data. It then states the mode and its frequency. Now my problem, I'm having trouble with an array of a "tie" of mode values (example: 8 and 9 both occurred 20 times) and it only displays 8 occuring 20 times. How can i fix it so it will display both items or more than two for that matter if there is a more-than-two way tie?
    Last edited by eazhar; 07-12-2002 at 09:00 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Manipulating Character arrays in functions.
    By kbro3 in forum C++ Programming
    Replies: 11
    Last Post: 08-16-2008, 02:24 AM
  2. functions using arrays
    By trprince in forum C Programming
    Replies: 30
    Last Post: 11-17-2007, 06:10 PM
  3. Arrays and Functions
    By KunoNoOni in forum Game Programming
    Replies: 12
    Last Post: 10-04-2005, 09:41 PM
  4. Arrays out-of-bounds in functions only?
    By KneeLess in forum C Programming
    Replies: 5
    Last Post: 11-03-2004, 06:46 PM
  5. Help Understanding Passing Arrays To Functions
    By jrahhali in forum C++ Programming
    Replies: 7
    Last Post: 04-10-2004, 02:57 PM