Histogram issues

This is a discussion on Histogram issues within the C++ Programming forums, part of the General Programming Boards category; Hey everyone how's it going I'm new here so it's nice to meet all of you. Well I have a ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    1

    Histogram issues

    Hey everyone how's it going I'm new here so it's nice to meet all of you. Well I have a question I'm supposed to write a histogram program where the uses inputs a set of numbers, followed by a -1. this would output a sideways histogram so for example is the use iputs 1, 2, 3, -1. the result would be
    *
    **
    ***
    For some reason I can't seem to get this I've actually tried everything so this is really annoying me to be honest. I think I'm in the right directoin with the code but to be honest I think it's completely wrong. Heres my code as is
    Code:
    #include <iostream>
    using namespace std;
    
    void printHistogram(int ar[], int size);
    
    int main( )
    {
        const int SIZE = 5;
        int HistoGram[SIZE];
        
        cout << "Enter a list of positive numbers.\n"
             << "Place a -1 at the end.\n";
    
        int next;
        cin >> next;
        while (next > 0)
        
        printHistogram(int ar[], int size)
       
        system("pause");
        return 0;
    }
    
    void printHistogram(int ar[], int size)
    {
      for (int i = 0; i < size; i++) 
      {
        int numStars = ar[i];
        for (int j = 0; j < numStars; j++)
          cout << '*';
        cout << endl;
      }
    }
    This just creates an infinite loop of *. Anyone think they can give me some help. Anything would be greatly appreciated. Sorry if this is kind of a fairly dum question. but thanks in advanced.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    There's no way the code you posted would compile, what with that "printHistogram(int ar[], int size)" in the middle of it all.

    Were you planning to do something with the data you read in? At the moment, you're just ignoring it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debugging issues
    By melodia in forum C Programming
    Replies: 1
    Last Post: 11-21-2010, 07:56 AM
  2. a histogram program
    By makonikor in forum C Programming
    Replies: 33
    Last Post: 04-17-2010, 02:17 AM
  3. a question on producing a pixel histogram of a picture
    By tracyhaha in forum C Programming
    Replies: 3
    Last Post: 04-07-2007, 08:27 AM
  4. hexdump issues
    By daluu in forum C Programming
    Replies: 2
    Last Post: 03-04-2003, 09:01 PM
  5. Still can't print a Histogram from fail input
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 07-11-2002, 01:24 PM

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