Shapes Menu

i am supposed to make a menu similar to the code below that when you enter options 1-6 and for each option theres a shape and you have to enter in the dimensions of the shape and it will give back the surface area and the volume.

the code blow is how i want to start it but I'm not sure how to add the functions to do what i said i want. i was absent from the class that went over how to do this. so if anyone could help me that'll be great.

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
  #include <iostream>

using namespace std;

int main()
{
    int choice;
    bool gameOn = true;
    while (gameOn != false){
        cout << "*******************************\n";
        cout << " 1 - Cube\n";
        cout << " 2 - Sphere\n";
        cout << " 3 - RetangularPrism\n";
        cout << " 4 - Cone\n";
        cout << " 5 - Cylinder\n";
        cout << " 6 - Exit\n";
        cout << " Enter your choice and press return: ";
      
        cin >> choice;
//the code above is what i need the functions for.  below is what I'm having trouble with. 
        switch (choice)
        {
            case 1:
                cout << "Volume and Surface Area\n"
                // rest of code here
                break;
            case 2:
                cout << "Volume and Surface Area\n"
                // rest of code here
                break;
            case 3:
                cout << "Volume and Surface Area\n"
                // rest of code here
                break;
            case 4:
                cout << "Volume and Surface Area\n"
                // rest of code here
                break;
            case 5:
                cout << "Volume and Surface Area\n"
                // rest of code here
                break;
            case 6:
                cout << "End of Program.\n";
                gameOn = false;
                break;
            default:
                cout << "Not a Valid Choice. \n";
                cout << "Choose again.\n";
                cin >> choice;
                break;
        }
        
    }
    return 0;
}
Start with asking the user to input the dimensions of the shape they chose.

I'm not sure what you want to happen after that - are you supposed to compute other properties of the shape? I can't imagine you'd be drawing 3D figures in the console.
No I'm not drawing any shapes. What I want to happen is they input the dimensions of the shape and then it will output the volume and the surface area of the shape. That's what I'm having trouble with. I don't know where to put that code.

So what I want it to look like is this

1) shape 1
2) shape 2
3) shape 3
4) shape 4
5) shape 5
6) quit

//Then let's say you select shape one and let's say that's a square.

"Enter the Side Length"
5
"Volume:: 25
"Surface Area:: 150

Then it goes back to the 6 option menu above.


If you would want to add functions into your current code, it would be a pain in the a**.

Because these shapes have different formulas, (the SA of a cube is different than the SA of a cyninder), you would need a seperate function for each shape with arguments for all the information uniquely necessary for that shape. It would honestly be more efficient to just add all the information in the cases.

I'm going to tell you what is needed to accomplish it, I'm sure you can figure it out from here.

-You need to ask for and get input for all the properties of each shape. (I.e. If case cube, ask for length of side)

-You need to calculate the volume and SA's of each shape. (That's just formulas, you can look them up)

-And finally, you have to output the answers to these using cout << (variable name or equation)

All of these things could go in a case, unless your teacher specifically said to use functions, in which case you can make a custom function propsOfCylinder(double r, double h) {} for each shape and go from there. Good luck :D Feel free to reply with questions
For this simple assignment, you would put the code for each shape inside the switch statement.

Note that in a real world scenario you would use a more modular approach, though.
so it would be like this?

1
2
3
4
5
6
7
8
9
10
11

             case 1:
                double side=0.0;
                cout << "Side?";
                cin >> side;
                double volume= pow(side,3.0);
                cout<<"Volume::"<<volume<<"\n";
                double SurA= 6*pow(side,2.0);
                cout<<"Surface Area:: "<<SurA<<"\n";
                break;


and just change the formulas to match the shapes?
Last edited on
Yes, that's the idea. Don't forget some shapes are more complicated than just asking for a side length.
so i went through, put all the formulas into the cases, and now for cases 2-6 and the default case i get the message "Switch Case is in protected scope." how would i go about fixing that?
i was actually able to fix it. i just separated each case in {}. it works fine now. thanks for the help
Topic archived. No new replies allowed.