Page 1 of 1

New Problem arrised in c++

Posted: Wed Nov 24, 2004 5:50 pm
by TISARKER
#include<stdio.h>
void main()
{
float n,a;
while(scanf("%f%f",&n,&a)==2)
{
printf("%f",n*a);
}
}

When I give n=100.00 , a=43.12 as input it
then gives 4311.999893 as results

When I give n=100.00 , a=43.123 as input it
then gives 4312.300110 as results

So I am not getting the actual result.
But How can I get it?

Re: New Problem arrised in c++

Posted: Wed Nov 24, 2004 6:14 pm
by CDiMa
TISARKER wrote:So I am not getting the actual result.
But How can I get it?
floats don't have the necessary precision required to solve problems. Use doubles instead...

Ciao!!!

Claudio

Re: New Problem arrised in c++

Posted: Wed Nov 24, 2004 8:34 pm
by TISARKER
Ok.
But Ihis problem is arrised in 147(dollars)problem too.
Are u sure by changing float to double without adding 0.5
problem 147(dollars) will be accepted?But I get wong answer.