New to C++ having strange math issues

Posted 31 August 2010 - 06:54 AM

Hello all, I am taking a class which requires me to work in C++. Being fairly competent in Java, C#, and Python I am pretty familiar with programming techniques, but this particular problem has me stumped. The assignment calls for me to create objects for particular shapes, and then calculate the volume of these shapes and do some calculations with them. Two of the shapes are Cone and Cylinder, and their volumes can be calculated as:
Cylinder volume = PI*radius^2*Height
Cone volume = 1/3(PI*radius^2*Height)

I was having some trouble getting the calculations to work, and so in the name of troubleshooting I implemented the calculation with the same formula to verify that I am getting the same results. Given the same data, I am returning different answers. So here is some code: