// Get card number
long n = get_long("Number: ");
// Count length
int i = 0;
long cc = n;
while (cc > 0)
{
cc = cc / 10;
i++;
}
Source: https://medium.com/swlh/cs50-pset-1-credit-c7996fb0a837

Source: https://medium.com/swlh/cs50-pset-1-credit-c7996fb0a837

It is mentioned:

We can then determine the length of the number by continuously dividing by 10, effectively knocking a digit off the end each time through the while loop until there are no digits left.

What I see is that cc = cc / 10 will keep on running with cc tending towards smaller and smaller fraction but not zero.

Suppose, finally afer cc/10, left with 9. Then 9/10, which is a fraction and not an integer. Seeking insight what happens at this stage.

I understand cc too an integer type (long integer), cc cannot be fraction.

Reply

https://cs50.stackexchange.com/questions/41921/pset1-credit-length-of-the-number-by-continuously-dividing-by-10[learn_press_profile]