# Thread: Help with simple program

1. ## Help with simple program

Hey all, there might be a solution to my problem in the tutorials but unfortunately I've procrastinated to the point where I need a solution a little quicker :/

The program I am writing is designed to take a number from a user and determine how many of each digit it contains.. pretty basic.

For example, 2345. Has 2 thousands, 3 hundreds, 4 tens and 5 ones.

I have the program written and everything works fine except I always get '0' for ones. I was hoping someone could take a look at it and let me know what I'm overlooking.

Code:
#include <stdio.h>

main(void)
{
int a, b, c, d, thousand, hundred, ten, one;
thousand = 1000;
hundred = 100;
ten = 10;
one = 1;

printf("Enter a Number: \n");
scanf("%d", &a);

b = a%thousand;
c = b%hundred;
d = c%one;

printf("%d THOUSANDS\n", a / thousand);
printf("%d HUNDREDS\n", b / hundred);
printf("%d TENS\n", c / ten);
printf("%d ONES\n", d);

return 0;

}
I am new to C so I know there is probably a quicker way to do all of this but you live you learn, eh?

Thanks in advance to anyone who takes up any of their time to look it over.

2. any number mod 1 gives 0
try
Code:
d = c&#37;ten;
Kurt

3. Now that you pointed it out, that seems like an obvious mistake. *slaps forehead*

Thank you very much for the help!

4. i think you have a class mate asking the same question in this board. It wasnt too long. I guess it was yesterday.

ssharish2005

5. Yeah, right after I asked the question I noticed that guy's thread. Sorry about posting a similar one.

/me takes time to check first next time