can you please

can you help me please on how to use the squared in calculating the volume of a cone?? i am a beginner using C++... please do help me... thanks for all the help and god blesss.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
using namespace std;

main()

{

int Pi, r, h, v;

cout << "Enter the Radius: ";
cin >> r;

cout << "Enter the Hieght: ";
cin >> h;

Pi=3.1416287;
v = (1/3)Pi(r*r)h;

cout << "The Volume is: " <<v;

return 0;

}





its killing me...
Last edited on
Prepare to have your mind blown: the square of x is x*x.
v = (1.0/3.0) * Pi * (r*r) * h;
closed account (z05DSL3A)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;

int main()
{

    double Pi, r, h, v;

    cout << "Enter the Radius: ";
    cin >> r;

    cout << "Enter the Hieght: ";
    cin >> h;

    Pi=3.1415926535897932384626433832795;
    v = (1.0/3.0)*Pi*(r*r)*h;

    cout << "The Volume is: " <<v << endl; 

    return 0;

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

int main()
{
	double Pi, v, r h;

	cout << "Enter the Radius: ";
	cin >> r;

	cout << "Enter the Hieght: ";
	cin >> h;

	Pi=3.1416287;
	v = (1.0/3.0) * Pi * (r*r) * h;

	cout << "The Volume is: " <<v;

	return 0;
}


You can't exclude the multiplication operator when performing multiplication.

You also had pi as an integer. Integers can't have fractions, so it needs to be a double. The same applies to the rest of the rest of your variables.

When you type numbers such as '1' and '3' they are automatically interpreted by the compiler as integers. To have the compiler understand them as doubles you have to write them as '1.0' and '3.0'.
Last edited on
Topic archived. No new replies allowed.