Hi, I am new to programming and am having trouble with this homework assignment. I am confused about how to implement the histogram and frequency. Any help will be greatly appreciated. :)

// Frequency distribution and bar graph program. User inputs 10 #s that range from 5-15 and is checked for validation.
// Prints the # of times each score occurs and also prints a horizontal bar graph that plots the non-0 frequency counts.

#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
	// create array to store #s
	const int SIZE = 10;
	int num[SIZE];
	int i = 0;

		while (true)
			// get 10 numbers from user
			cout << "Please enter 10 #s b/w 5-15 (separate each # w/a space): ";
			cin >> num[i];

			// verify if valid, if not loop
			if (num[i] >= 5 && num[i] <= 15) break;
			cout << "All numbers are not b/w 5-15. Please try entering them again." << endl;
		} // while

	// loop for frequency & histogram
	for(i = 0; i < SIZE; i++)

		int j;
		for(j=0; j<num[i]; j++)
			cout << "*";
		} // for
	} // for

	return 0;

The frequency of a number is how many times it appears in the list. A histogram is a visual representation of the frequency. Start by ignoring the histogram and only display the frequencies as a list of counts.

I can think of two easy ways to count the frequency. A nested loop over the numbers is one way, and storing the counts in a second array is another. Both of those are good options because there are not enough numbers to make the nested loop method too slow, and the range is not big enough to make the second array a memory hog.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.