Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the area come back as 0?

Tags:

c++

pi

Here's the code.

int a;
int pi = 3.14;
int area;
int main()
{
    cout << "Input the radius of the circle ";
    cin >> a;

    a *= a *= pi >> area;

    cout << "The area is " << area;


}
like image 970
Matt Bettinson Avatar asked Jan 15 '11 15:01

Matt Bettinson


People also ask

Is area can be zero?

The definite integral can be used to calculate net signed area, which is the area above the x-axis less the area below the x-axis. Net signed area can be positive, negative, or zero.

What does it mean when area under curve is 0?

If the function calculates change in position with respect to time (velocity), then if the value of the integral is 0 it means the displacement is 0, i.e you are back to your starting point, either because you stayed there the whole time (V=0), or you moved but then turned around and came back.

Should the area be always positive?

Finally, unlike the area under a curve that we looked at in the previous chapter the area between two curves will always be positive. If we get a negative number or zero we can be sure that we've made a mistake somewhere and will need to go back and find it.

How do you calculate the area under a curve?

The area under a curve between two points is found out by doing a definite integral between the two points. To find the area under the curve y = f(x) between x = a & x = b, integrate y = f(x) between the limits of a and b. This area can be calculated using integration with given limits.


1 Answers

The >> operator when used with numbers is right shift, not assignment. You want something like

area = a * a * pi;

Update

You also need to use a floating point type or your answer won't be what you expect.

float a;
float pi = 3.14f;
float area;
like image 148
Alex Avatar answered Oct 06 '22 17:10

Alex