Double circle


Hi there,
I Was reading some codes of C++, there something called a circle, double circle. I Don't understand what it's for, I couldnt find it on the search.

Here the code: -

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;

#define PI 3.14159
#define NEWLINE '\n'

int main ()
{
  double r=5.0;               // radius
  double circle;

  circle = 2 * PI * r;
  cout << circle;
  cout << NEWLINE;

  return 0;
}


Out come is:

31.4159

I Can't see to understand the the circle is for.

Any help?
Last edited on
Uh, circle is assigned the perimeter of a circle with the radius 5.
If your question was about double, it is a data type that can hold more than just integers. See
http://en.wikipedia.org/wiki/Floating_point
This is more of a mathematical matter...

The formula you see there, circle = 2 * PI * r; Is the formula for calculating a circles diameter.
When using C++ all variables fall into certain data types (I'm not going to get into enum, or anything fancy) typically the ones you will be dealing with the most are:
int
float
double
char

int is simply a non-floating point number
float can be any int, with a decimal at the end (20.257 for example)
double is the same as float, but with a higher level of precision.
char can be any 1 character (letter, number, etc.)

When you are declaring a variable you typically pick a data type (in this case, since pi is a floating point value, float or double would be appropriate) and then name the variable

Thus we end up with a declaraction that looks like this

Datatype VariableName;
in this case
double circle;
AngelHoof wrote:
The formula you see there, circle = 2 * PI * r; Is the formula for calculating a circles diameter.


Not for the diameter, for the circumference.
Topic archived. No new replies allowed.