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;
}
}