Thread: Counting the # of items in an array

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    36

    Counting the # of items in an array

    I have this prog and what I need to do is have the user input their numbers and print the array, Then, for it to count the number of times the number was inputted and print a histogram of the number of times it was used. EX:

    2.......10........3.5
    4.......3.5 ..........21
    3.........8...........7
    //etc....

    response ........# of times....... Histogram
    1 .................... 2 ..................**
    2 ................... 1 .......................*
    //etc....

    Here is what I have and I am unsure of the last few lines. I copied the last couple of lines from another example, I just included it because I know it will look somewhat to those lines. Please help, any help appreciated!

    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    const int numrow = 5;
    const int numcol = 3;
    
    int main ()
    {
    double nums[numrow][numcol];
    	
    	for (int i = 0; i <numrow; i++)
    {
    	for (int j = 0; j < numcol; j++)
    {
    	cout << "enter grades for row # " << (i + 1)<< ": ";
    	cin >> nums [i][j];
    }
    }
    	for (int a = 0; a < numrow; a++)
    {
                    for (int b = 0; b < numcol; b++)
    {
                   cout << setw (4) << nums [a][b];
    }
                   cout << "Response" << setw( 13 ) << "Frequency"
                    << setw( 17 ) << "Histogram" << endl;
    
       for ( int i; i < numrow; i++ ) 
    {
          cout << setw( 7 ) << i << setw( 13 ) 
               << n[ i ] << setw( 9 );
    
          for ( int j = 0; j < n[ i ]; j++ )   // print one bar
          cout << '*';
       
       cout << endl;
    }
       return 0;
    }
    Last edited by stevedawg85; 03-23-2006 at 08:20 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Here is what I have and I am unsure of the last few lines. I copied the last couple of lines from another example, I just included it because I know it will look somewhat to those lines.
    What do you think those 'last few lines' are supposed to do?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Modify an single passed array element
    By swgh in forum C Programming
    Replies: 3
    Last Post: 08-04-2007, 08:58 AM
  2. Delete duplicate items in an array
    By chaos in forum C Programming
    Replies: 4
    Last Post: 06-16-2005, 02:51 PM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. Replies: 5
    Last Post: 11-20-2001, 12:48 PM