Counting occurence of #'s

Write a program that accepts any amount of numbers within 50

"0" acts as an end of input

A count will begin and display every digit and how many times that digit occurs.

for (int i = 0; i < size; i++)
{
counter = 0;
if (list[i] == 0)
break;

for (int j = 0; j < size; j++)
{
if (list[j] == list[i])
counter++;
}

cout << i << " Occured " << counter << "times. " << endl;



}
Ok? I don't see a question.
I apologize,

I cannot get the output to display the proper count.

This is what I have done so far.

I feel like there is an error in my second loop - the counter that shows the the amount of time that each element occurs is not accurate.

int main()
{

const int size = 50;
int list[size];
int counter = 0;

cout << "Enter any number of integers between 1 - 50: " << endl;

for (int i = 0; i < size; i++)
{
cin >> list[i];
if (list[i] == 0)
break;
}





for (int i = 0; i < size; i++)
{
counter = 0;
if (list[i] == 0)
break;

for (int j = 0; j < size; j++)
{
if (list[j] == list[i])
counter++;
}

cout << i << " Occured " << counter << "times. " << endl;



}

return 0;
}
Please use code tags. As for your second loop, there is no need for a
 
if(list i ==0) break;

As far as the count goes, it doesn't seem that hard. In pseudocode it should be like this:
1
2
3
4
5
iterate through the numbers 1 to 50
	iterate through every number entered
		increment count everytime the number that is 1-50 appears increment count
	if count is not equal to 0 
		output the count
Topic archived. No new replies allowed.