Well, using the sample you found, we can quite easily infer a code for you.
The first line says int first = 321/100;
, which returns 3 (integer division is the euclidian one). 3 is indeed the first integer in 321 so that's a good thing. However, we have a 4 digit number, let's try replacing 100 with 1000:
int first = 4321/1000;
This does return 4 !
Let's try adapting the rest of your code (plus I put your four digit number in the variable entry
).
int entry = 4321;
int first = entry/1000;
int second = entry/100 - first*10;
int third = entry/10 - first*100 - second*10;
int fourth = entry - first*1000 - second*100 - third*10;
second
will be entry/100
(43) minus first*10
(40), so we're okay.
third
is then 432 - 400 - 30
which turns to 2. This also works till fourth
.
For more-than-four digits, you may want to use a for-loop and maybe some modulos though.