Why the desired precision is not coming

#include
using namespace std;
int main()
{
int n,p;
cin>>n>>p;
double inc=1.0,sqrt=1.0;
for(int i=0;i<p;i++)
{
while(sqrt*sqrt<=n)
{
sqrt=sqrt+inc;
}
sqrt=sqrt-inc;
inc=inc/10;
}
cout<<sqrt;
return 0;
}

take n=12 and p(precision)=8 output: 3.4641
why is it so the precision we get is 5 not 8

@namangarg31 hey use printf for precision,here is example:
In C, there is a format specifier in C. To print 4 digits after dot, we can use 0.4f in printf(). Below is program to demonstrate the same.
// C program to set precision in floating point numbers
// using format specifier
#include<stdio.h>

int main()
{
float num = 5.48958123;

// 4 digits after the decimal point   
printf("%0.4f", num);  
return 0; 

}
Output:
5.4896

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.