1. ## Using Double...

I made this code for show how many digits have a number, example...

Enter a number: 546
The number have 3 digits.

with int he works fine, but i canīt make he work with double.

Code:
```#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>

main()
{
double n, c;
char resposta = 's';

do
{

printf("\n\n");
printf("          ****************************************************\n");
printf("          *   Infomar a quantidade de digitos de um numero:  *\n");
printf("          ****************************************************\n");

printf("\n Digite um numero: ");
scanf("%lf", &n);

for(c = 0; n; n /= 10)
c++;

printf("\n ----> O numero possui %lf digitos.", c);

printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printf(" Deseja Continuar S/N?: ");
scanf( "\n %c", &resposta );
system("cls");
}while(toupper(resposta) == 'S');
}```

2. What's the problem? Guess: it never ends.

Because if you have 12.2 inserted you will have:
12.2 / 10 = 1.22 / 10 = 0.122 / 10 = 0.0122 etc etc. So n will alwasy be !=0 thus true that the while loop will never end. You might want n < 0 or n < 0.0001 (something small).

Cheers

3. Originally Posted by C_ntua
or n < 0.0001 (something small).
This is called an epsilon value and is essential when comparing doubles to just about any value.

QuantumPete