New Problem arrised in c++

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
TISARKER
Learning poster
Posts: 88
Joined: Tue Oct 12, 2004 6:45 pm
Location: Bangladesh
Contact:

New Problem arrised in c++

Post 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?
Mr. Arithmetic logic Unit
CDiMa
Experienced poster
Posts: 214
Joined: Fri Oct 17, 2003 5:49 pm
Location: Genova

Re: New Problem arrised in c++

Post 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
TISARKER
Learning poster
Posts: 88
Joined: Tue Oct 12, 2004 6:45 pm
Location: Bangladesh
Contact:

Re: New Problem arrised in c++

Post 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.
Mr. Arithmetic logic Unit
Post Reply

Return to “C++”