> a;...">

Why does the region return 0?

Here is 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; } 
+6
c ++ pi
source share
8 answers

The area of ​​the circle is pi * r * r, so you would like to do;

a = a * a * pi

Hope that helps

and they should all be floating.

+2
source share

The >> operator when used with numbers is a shift to the right, not an assignment. Do you want something like

 area = a * a * pi; 

Update

You also need to use a floating point type, otherwise your answer will not be what you expect.

 float a; float pi = 3.14f; float area; 
+13
source share

I do not have the patience to decrypt your strange code. What about only area = a * a * pi ?

+7
source share

Your code makes no sense.

pi (and all your other variables) must be double or float, ... not int. Int can only contain an integer. And pi is obviously not integral.

a *= a *= pi >> area; must be area = a * a * pi;

>> is a bitwig, not an assignment to the right side
*= multiplied, not just multiplied. i.e. it looks like left=left*right

+6
source share

Your code does not do what I think you would like to do. You do not assign variables with >> ; that is, only to extract the stream (and bit rate).

Also, a *= a *= pi probably doesn't do what you think.

Also, you need floating point values, not int . "Int" pi is 3.

In addition, you should have error checking when retrieving your stream!

Try:

 int main() { const float pi = 3.14; float a; cout << "Input the radius of the circle "; if (!(cin >> a)) { cout << "Invalid radius!"; return 1; } float area = (a * a * pi); cout << "The area is " << area; } 
+2
source share
 int pi = 3.14; 

Invalid data type. Assigning a double int value? It is not right.

Write this:

 double pi = 3.14; 

And similarly change the other data types to double .

+2
source share

Because you use int or integer for all your variables. Do you want to use double or even float s. ( double more precisely).

+1
source share

All your variables are declared as ints, which simply discard any fractional part assigned to it. To work with floating point values, use double instead.

In addition, your equation is almost incomprehensible. Not sure what you are trying to do there.

+1
source share

All Articles