Urgent! Please help.

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);}}
}








return(0);
}
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.

Your code, but a different looks

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#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);
            }
        }
    }
    return(0);
}
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.
Topic archived. No new replies allowed.