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?



LinkBack URL
About LinkBacks



.