Define a macro

How can I define a macro, Area? I have to make a program that calculates the area of a cirlce using PI times r times r.
If I understand you correctly, you want to use a macro to find the area of a circle. In my view, the best way would be to do something like this, using a function and a constant instead of macros:
1
2
3
4
5
const double PI = 3.14159;        // Use constants instead of macros in C++

double circle_area (double r) {   // Use a function. They're much more safe 
     return (PI * r * r);                  // than macros.
}

If you really wanted to though, I believe that the correct way to use macros in this case would be
1
2
#define PI 3.14159
#define Area (r) r * r * PI   // Not sure about this. I don't use macros...  

Hope that this helps!
Topic archived. No new replies allowed.