Odd results from simple circle area/circumference calculation

Hi all,

I'm following a basic tutorial and trying to solve the related assignments using only what's been covered up to that point. The one I'm currently working on tasks you with finding the area and circumference of a circle given its radius, and with the value of *pi* set to 3.14.

Having set up my variables thus:

Code:

`double pi = 3.14, r, a, c`

presumably the following should give me what I need:

Code:

`a = pi*r*r`

c = 2*pi*r

and it works for most values of *r*, but not all. *r=3*, for instance, returns *a = 28.259999999999998* instead of the expected *a = 28.26*. Various seemingly random numbers yield similar results. Between 1 and 50, they are: 3, 6, 12, 24, 29, 39, 43, 45 and 48. For the circumference, the following values of *r* in the same region return unexpected results: 5, 10, 19, 20, 38, 39 and 40.

Changing the area calculation to:

corrects some cases (not all), but introduces new ones, and I don't understand why the brackets would make a difference in any case. I can't get the circumference calculation to change its behavior at all.

Obviously I am missing something here, but I can't figure out what it is. Any ideas?

(I know there are better ways of solving either calculation, but like I said, I'm trying to use only what's been covered in the tutorial thus far.)