I am making a program that will calculate the surface are and volume of geometric figures, with C++ visual studio 6. The variable sora stands for surface are or volume. Although the portion of the program that calculates spheres, and cylinders work I am not sure why the prism and the pyramid are being skipped, leading me straight to the return(0);. I would appreciate if someone could tell me the error in my code.
Thanks in advance.
#include <iostream.h>
#include <math.h>
#define PI 3.14159265
int main()
{
double radius;
double height;
int sides;
double halfsidelength;
double sidelength;
double apothem;
double Base;
double perimeter;
double slantheight;
char sora;
char shape;
cout << "Geometric figure surface area and volume calculator\n";
cout << "What kind of shape are you using?\n";
cout << "Sphere(s), Cylinder(y), Prism(p), Pyramid(d)";
cin >> shape;
if(shape=='s'){
cout << "Are you calculating the surface area(s) or the volume(v)?";
cin >> sora;
if(sora=='s'){
cout << "Enter the radius: ";
cin >> radius;
cout << "Surface Area = "<<(4*PI*(radius*radius))<<endl;
cout << "possible restart program";}
else if(sora=='v'){
cout << "Enter the radius: ";
cin >> radius;
cout << "Volume = "<<((4*PI*(radius*radius*radius))/3);
cout << "possible restart program";}}
else if(shape=='y'){
cout << "Are you calculating the surface area(s) or the volume(v)?";
cin >> sora;
if(sora=='s'){
cout << "Enter the radius: ";
cin >> radius;
cout << "Enter the height: ";
cin >> height;
cout << "Surface Area = "<<(2*(PI*(radius*radius)+(2*(PI*radius)*height)));
cout << "possible restart program";}
else if(sora=='v'){
cout << "Enter the radius: ";
cin >> radius;
cout << "Enter the height: ";
cin >> height;
cout << "Volume = "<<(PI*(radius*radius)*height);
cout << "possible restart program";}
else if(shape=='p'){
cout << "How many sides does the base have?";
cin >> sides;
char sidelengthq;
cout << "Do you know the side length?(Y/N)";
cin >> sidelengthq;
if(sidelengthq=='y'){
cout << "Enter the side length: ";
cin >> sidelength;}
cout << "Do you know the apothem?(Y/N)";
char apothemq;
cin >> apothemq;
if(apothemq=='y'){
cout << "Enter the side length: ";
cin >> apothem;}
if(apothemq=='y' && sidelengthq=='y'){
Base=(sides*sidelength)*apothem;}
else if(apothemq=='y' && sidelengthq=='n'){
Base=(apothem*apothem)*sides* tan(180/sides);}
else if(apothemq=='n' && sidelengthq=='y'){
Base=((sidelength*sidelength)*sides)/4*tan(360/sides);}
perimeter=sidelength*sides;
if(sora=='s'){
cout << "Surface Area = "<<(2*Base)+(2*perimeter);
cout << "possible restart program";}
if(sora=='a'){
cout << "Enter the height: ";
cin >> height;
cout << "Volume = "<<Base*height;
cout << "possible restart program";}}
else if(shape=='d'){
cout << "Do you know the slant height?(Y/N)";
char slantheightq;
cin >> slantheightq;
cout << "Enter the perimeter of the base: ";
cout << "Do you know the base(Y/N): ";
char Baseq;
cin >> Baseq;
if(Baseq=='y'){
cin >> Base;}
else if(Baseq=='n'){
cout << "Enter the number of sides the Base has: ";
cin >> sides;
sidelength=perimeter/sides;
cout << "Do you know the apothem?(Y/N)";
char apothemq1;
cin >> apothemq1;
if(apothemq1=='y')
cout << "Enter the side length: ";
cin >> apothem;
if(apothemq1=='y')
Base=(sides*sidelength)*apothem;
else if(apothemq1=='n')
Base=((sidelength*sidelength)*sides)/4*tan(360/sides);}
cout << "Are you calculating the surface area(s) or the volume(v)?";
cin >> sora;
if(sora=='s'){
if(slantheightq=='y')
cout << "Surface Area = "<<(1/2)*perimeter*slantheight+Base;
else if(slantheightq=='n')
halfsidelength=sidelength/2;
cout << "Enter the height: ";
cin >> height;
slantheight= sqrt((height*height)+(halfsidelength*halfsidelength));
cout << "Surface Area = "<<(1/2)*perimeter*slantheight+Base;}
if(sora=='v'){
cout << "Volume = "<<((1/3)*Base*height);}}
}
Why is so many threads marked with urgent? Are you an Egyptian king that will soon die so you need this program to work otherwise you can not finish the pyramid in time?
Please put your code in code tags . That way the code formatting is kept intact and it's much easier to read.
now at line number 63 in your code (my post)
replace the } with }} (i.e. add one more)
.
And let this be a lesson to you about the importance of code clarity and paranthesis
I apologize if the "Urgent" is undesirable, and i will make sure to include the code tags next time, I am new, but that shouldn't be an excuse. Thank you for the help I will try this out as soon as i'm able.