First Switch Not Executing properly.Problem Of brackets?

So I Wrote A Program That goes like this:
1.Area (Takes User Input if he wants to calculate are
2.Perimeter or perimter)


And Then Displays Figure Options such as square,circle etc and takes their respective measurements and shows the output but problem is only Perimeter option is working.

The Area (1) input takes 1,also displays figures,also displays the taking input statements but at final part that is calculations it randomy shows the perimeter menu? I don't know why this is happening,maybe brackets?
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
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
    float rl,rb,sl,trh,trb,cr;
    int choice1,choicea,choicep;
    cout<<"\n1.Area\n2.Perimeter";
    cin>>choice1;
    switch(choice1)
    {
        case 1 : system("cls");
        cout<<"\n1.Square\n2.Rectangle\n3.Circle\n4.Triangle";
        cin>>choicea;
        switch(choicea)
        {
            case 1 : cout<<"\nEnter The Length Of Square :";
            cin>>sl;
            cout<<"The Area Of Square = "<< sl * 4;
            break;
            case 2 : cout<<"\nEnter The Length and Breadth Of Rectangle :";
            cin>>rl>>rb;
            cout<<"\nThe Area Of Rectangle = "<<rl * rb;
            break;
            case 3 : cout<<"\nEnter The Radius Of Circle :";
            cin>>cr;
            cout<<"\nThe Area Of Circle = "<< 3.14 * cr * cr;
            break;
            case 4 : cout<<"\nEnter Base And Height Of Triangle :";
            cin>>trh>>trb;
            cout<<"\nThe Area of Triangle = "<< 0.5 * trb * trh;
            break;
            default : cout<<"\nWrong CHOICE!!!!!!!!";
            break;
        }
        case 2 : system("cls");
        cout<<"\n1.Circle\n2.Square\n3.Rectangle";
        cin>>choicep;
        switch(choicep)
        {
            case 1 : cout<<"\nEnter The Radius Of The Circle :";
            cin>>cr;
            cout<<"\nThe Perimeter Of Circle = "<<2 * 3.14 * cr;
            break;
            case 2 : cout<<"\nEnter The Length Of Square :";
            cin>>sl;
            cout<<"\nThe Perimeter Of Square = "<< 4 * sl;
            break;
            case 3 : cout<<"\nEnter The Length and Breadth Of Rectangle ";
            cin>>rl>>rb;
            cout<<"\nThe Perimeter Of Rectangle is = "<<2*(rb + rl);
            break;
            default : cout<<"\nWrong CHOICEEEE!!!!!!!!!";
            break;
        }


    }
    return 0;
}



Help Would Be Appreciated.
Thank You.

I am using codeblocks.
Last edited on
closed account (E0p9LyTq)
Add a break; statement at the end of your inner switch, line 36.

Thank you for using code tags, that is very helpful. :)

PS, learning to use some whitespace would help make your source much easier to read:
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
#include<iostream>
#include<stdlib.h>

using namespace std;

int main()
{
   float rl, rb, sl, trh, trb, cr;
   int choice1, choicea, choicep;

   cout << "\n1.Area\n2.Perimeter";
   cin >> choice1;

   switch (choice1)
   {
   case 1:
      system("cls");
      cout << "\n1.Square\n2.Rectangle\n3.Circle\n4.Triangle";
      cin >> choicea;

      switch (choicea)
      {
      case 1: cout << "\nEnter The Length Of Square :";
         cin >> sl;
         cout << "The Area Of Square = " << sl * 4;
         break;
      
      case 2: cout << "\nEnter The Length and Breadth Of Rectangle :";
         cin >> rl >> rb;
         cout << "\nThe Area Of Rectangle = " << rl * rb;
         break;
      
      case 3: cout << "\nEnter The Radius Of Circle :";
         cin >> cr;
         cout << "\nThe Area Of Circle = " << 3.14 * cr * cr;
         break;
      
      case 4: cout << "\nEnter Base And Height Of Triangle :";
         cin >> trh >> trb;
         cout << "\nThe Area of Triangle = " << 0.5 * trb * trh;
         break;
      
      default: cout << "\nWrong CHOICE!!!!!!!!";
         break;
      }
      break; // NOTE this break!!!

   case 2:
      system("cls");
      cout << "\n1.Circle\n2.Square\n3.Rectangle";
      cin >> choicep;
      
      switch (choicep)
      {
      case 1: cout << "\nEnter The Radius Of The Circle :";
         cin >> cr;
         cout << "\nThe Perimeter Of Circle = " << 2 * 3.14 * cr;
         break;
      
      case 2: cout << "\nEnter The Length Of Square :";
         cin >> sl;
         cout << "\nThe Perimeter Of Square = " << 4 * sl;
         break;
      
      case 3: cout << "\nEnter The Length and Breadth Of Rectangle ";
         cin >> rl >> rb;
         cout << "\nThe Perimeter Of Rectangle is = " << 2 * (rb + rl);
         break;
      
      default: cout << "\nWrong CHOICEEEE!!!!!!!!!";
         break;
      }

   default: cout << "\nWrong CHOICEEEE!!!!!!!!!";
   }

   return 0;
}
Ah Thank You So Much!!!!! Now That i have fixed this,i can start expanding this program further! Much Appreciated.
Topic archived. No new replies allowed.