# Help with number counting program

• 10-26-2007
Turtal
Help with number counting program
Honestly ya, it's a class program, but im not asking for the answer, just help.

I have to create a program that lets the user input as many numbers (1 through 9) as he/she wants and use 0 to cancel the input and continue the program which will then take the numbers and display how many times each number was entered. Say the user enter 1 2 1 1 3 4 3 2 , it would read out:
1: 3 time(s)
2: 2 time(s)
3: 2 time(s)
4: 1 time(s)
I've been playing around with some for loops and arrays (which we haven't been taught yet, so I'm guessing using arrays wouldn't be accepted), and keep keeping odd outputs.
Here are a few examples I've been playing with, non go up to 9 or, just some tests that Im thinking are taking me no where. Any help would be great.

Code:

```#include <stdio.h> int main(void) {         int i, j, k, counter;         counter = 0;                 printf("enter some ........\n");         while (i != 0)         {                 scanf("%d", &i);         }                 for(i > 0; i <= 9; i++)                 {                         if(i == 1)                         {                                 counter = counter + 1;                                 counter = k;                                 printf("1 was entered %d times\n", k);                                 }                                 }                                 system("PAUSE");                                 return 0; }```
Code:

```#include <stdio.h> int main(void) {  int i, j, k;  printf("Enter some numbers:\n");  while(i != 0){  scanf("%d", &i);       for(i > 0; i <= 9; i++)     {                 for(k = 1; k < 9; k++)                 {                         printf("k is %d", k);                 }           }     system("PAUSE");     return 0;     } }```
• 10-26-2007
Elysia
You'll need a loop, of course, that keeps the program asking for more numbers each time the user doesn't 0.
Check what the users enters and use counters to increment for each type, maybe.
Then output those variables after the loop is finished.

Think about it a little while. Maybe a solution will come to you.
• 04-24-2009
youngvito
I have been working on this exact same problem for days now and i would please like to see the solution to this problem.
• 04-24-2009
Imagine you had 9 cups in front of you, and I kept handing you a numbered piece of paper, over and over.

What could you do with those 9 cups to keep track of 9 digits, and help you count up (at the end), all the tallys of all the numbers. (not the sums, the tallys)

Get yourself 9 cups/jars/saucers, any 9 containers, and you sit down and start picking up numbered pieces of paper, and you will see the answer in 15 minutes, tops. (probably in 1).

Usually, we'd use an array or linked list for this, but you can use nine variables, just like you're using those nine cups, perfectly well.

Don't increment the "container". Increment the individual cup in your program.
• 04-24-2009
quzah
Shouldn't you be using ten containers, since there are ten digits? ;)

Quzah.
• 04-24-2009
Nope, they are counting up only nine digits. Zero is just to quit entry of digits.
• 04-24-2009
quzah
Well, if you're going to actually read the first post. :rolleyes:

Quzah.
• 04-24-2009
LOL! :p :p
• 04-24-2009
youngvito
I have a problem similar to this one. It is to find the maximum number in the list and count and print out the number of times it was entered. Can someone please help me.
• 04-24-2009
quzah
That's pretty much identical to this issue. Just add another variable to keep track of the max, and check for it in the loop. Post your code attempt.

Quzah.
• 04-24-2009
YoungVito, did you try the 9 cups and 9 digits on several pieces of paper, exercise?

No, you did not!

If you would, you'd have the answer by now. Instead, you're here again, looking for someone to code it up for you.

And what's ironic is that I already coded up this min and max example, just earlier today, for someone else. (TammyS, I believe).

So search for it with the forum search tool, or show your code attempt at doing this.

This is not rocket science. Give it a shot!
• 04-25-2009
youngvito
Here is my attempt at this program could someone please give me some advice.

insert
Code:

``` #include <stdio.h> int main() {     int max;     int i;     int current;     int numbers;     int count = 0;     printf("\nHow many numbers would you like to enter: ");     scanf("%d", &numbers);         for (i = 0; i < numbers; i++)     {         scanf("%d", &current);         if (max > current)         {           max = current;           count++;         }     }     printf("Max: %d    Number of times: %d\n", max, count);      system("PAUSE");            return 0; }```