Trying to understand C++

I am new to C++ programming and I am trying to understand this.
I am working on a program that is supposed to use the isosceles tringle and the Pythagorean Theorem. I am stuck on is the forumla for both. In the formulas they have second to the power of the base for the Volume and a second to the power of height.

My question: How would I be able to input this to C++ programming?

example: volume=A(sq)*h/3

my other question: why would this be /3 if the formula is really this?:

Volume=1/3bh
Last edited on
To answer question 1:
1
2
3
4
5
6
7
8
9
10
int main()
{
    float h, A, Volume; //Declare variables
    cin >> h >> A; //Get inputs

    Volume = A * h / 3.; //Calculate outputs

    cout << Volume; //Output result
    return 0;
}


To answer question 2:
(1/3)*b*h = b * h / 3
if A = b then this is true.

Last edited on
In the formulas they have second to the power of the base for the Volume and a second to the power of height.

What?

If this means base to power of 2 (base^2) then use: pow(base, exponential). There are a lot of overloading of this but double base, double exponential should cover you.

http://www.cplusplus.com/reference/clibrary/cmath/pow/

I didn't get what exactly you are asking so I may be wrong. In this article you can find square root (sqrt()) also although you can implement it with pow as well.
Ew don't use float. At least use double. Float is terribly imprecise
Thank you everyone! All of this info you have given me is a big help. Thank you so much. ^.^
Then how abut this formula?

s=sqrt(hpow2+(a/2)pow2)

This is to find the surface area of a triangle,
but the way I learned this formula is way different.

How does everything square off?
I know math but the comprehencion of how to get this in code is very confusing.
SA of triangle is
1/2 base * height
@ResidentBiscuit: float is fine depending on your requirements. If you're going to calculate a volume and then output the answer to 2 decimal places, why would you use a double? That's like using
for (long long i=0; i<2; i++)
Last edited on
Topic archived. No new replies allowed.