Please I just need some help finding out why the surface area is not coming out correctly. I just started the class a few weeks ago and i know it is probably something simple, but i have spent two days just going in circles trying everything i could think of. If someone could just maybe point me in the right direction. Thank you.

Also this is my first post so sorry if it is not done correctly.

#include <iostream>

#include <cmath>

using namespace std;

float height = 0; //height

float radius = 0; //radius

float slant = 0; //slant height

double surface = 0; //surface area

double volume = 0; // volume

double pi = 3.14159; //pi

float r = 0; //radius squared

float h = 0; //height squared

float s = 0; //s = r^2 + h^2 for slant height

int main()

{

cout <<"Please input the Height:" << endl;

cin >> height; //user enter height

cout <<"Please enter the Radius:" << endl;

cin >> radius; //user enter radius

r = pow (radius,2); //setting radius squared

h = pow (height,2); //setting height squared

slant = sqrt(r+h);

surface = pi * radius * (radius + sqrt(radius + slant));

volume = pi * (pow (radius,2)) * height/3;

cout << "Total Surface Area: " << surface << endl;

cout << "Volume: " << volume << endl;

system("pause");

return 0;

}

Also this is my first post so sorry if it is not done correctly.

#include <iostream>

#include <cmath>

using namespace std;

float height = 0; //height

float radius = 0; //radius

float slant = 0; //slant height

double surface = 0; //surface area

double volume = 0; // volume

double pi = 3.14159; //pi

float r = 0; //radius squared

float h = 0; //height squared

float s = 0; //s = r^2 + h^2 for slant height

int main()

{

cout <<"Please input the Height:" << endl;

cin >> height; //user enter height

cout <<"Please enter the Radius:" << endl;

cin >> radius; //user enter radius

r = pow (radius,2); //setting radius squared

h = pow (height,2); //setting height squared

slant = sqrt(r+h);

surface = pi * radius * (radius + sqrt(radius + slant));

volume = pi * (pow (radius,2)) * height/3;

cout << "Total Surface Area: " << surface << endl;

cout << "Volume: " << volume << endl;

system("pause");

return 0;

}

Last edited on

Sorry, the program is suppose to give both the surface area and volume of a cone given the height and radius. Forgot to mention that like a dumb.

Last edited on

Formula for surface area is incorrect.

Should be:

pi * (radius * radius) + pi * radius * slope height

Everything else works. Although, you should get rid of system("PAUSE");.

Should be:

pi * (radius * radius) + pi * radius * slope height

Everything else works. Although, you should get rid of system("PAUSE");.

Last edited on

Alright did it, works fine now thank you very much. I think that i just stared at it too long looking at everything but the obvious. Is there any particular reason why you recommended removing the pause? Because when I do the prgram runs though without stopping so I cant see my results. I am using visual studio 10, i dont know if that makes a difference.

thanks again

thanks again

Last edited on

I believe if you just hit ctrl-f5 it will run without debugging and puase automatically. And if you just hit f5 thats where it disappears//

Last edited on

About system: http://stackoverflow.com/questions/900666/system-calls-in-c-and-their-roles-in-programming

And yeah, always check your maths in these kind of programs, if the result is incorrect. ;)

And yeah, always check your maths in these kind of programs, if the result is incorrect. ;)

Alright thanks guys, I just went with the equation that was on my assignment. But it was different then the end result but this works now and I'm good to go. Thanks again.

Topic archived. No new replies allowed.