0

With the following code:

#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159;

int main() {

double x;
cin >> x; 

cout << "A=" << pi * x * x << endl; 

return 0; 
}

And inputting

100.64

I get the value 31819.3, while what I want is 31819.3103

I tried using set precision but that doesn't seem to work either. Why is this happening?

Aashir shukla
  • 93
  • 1
  • 9
  • 1
    Here's some interesting reading: [What Every Computer Scientist Should Know About Floating-Point Arithmetic](http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html) – 001 May 27 '16 at 13:40
  • https://ideone.com/9QdKYo <- `setprecision` works, but it's the number of digits not the number of decimals. – coyotte508 May 27 '16 at 13:44
  • BTW, don't use the non-standard header `bits/stdc++.h`. Get in the habit of only including necessary header files. – Thomas Matthews May 27 '16 at 14:41

0 Answers0