infinite loop switch statement

I enter a "2" to select area of a rectangle and then input two valid numbers but after I hit enter it asks the question again instead of exiting the switch statement

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
#include <iostream>
#include <fstream>
//Jacob Wilt
//Geometry Calculator
using namespace std;

int main()
{
    ofstream outfile;
    outfile.open("Geometry.txt");
    int x, radius, length, width, base, height;
    const double pie = 3.14;
    cout << "1. Calculate the Area of a Circle:\n2. Calculate the Area of a Rectangle:\n3. Calculate the Area of a Triangle:";
    cout << "\n4. Quit:\n\nEnter your choice (1-4):\n";
    cin >> x;
    while (x > 0 && x < 4)
    {
    switch(x)
    {
    case 1:
        {
            cout << "Enter the radius of the Circle.\n";
            cin >> radius;
            if (radius >= 0)
            {
                cout << "The area of the circle is " << radius * radius * pie << "\n\n";
            }
            else
            {
                cout << "Invalid Input!!";
            }
            break;
        }
    case 2:
        {
            cout << "Enter the length and width of the Rectangle.\n";
            cin >> length >> width;
            if (length >= 0 && width >= 0)
            {
                cout << "The area of the Rectangle is " << length * width << "\n\n";
                break;
            }
            else
            {
                cout << "Invalid Input!!";
            }
            break;
        }
    case 3:
        {
            cout << "Enter the base and height of the Triangle.\n";
            cin >> base >> height;
            if (base >= 0 && height >= 0)
            {
                cout << "The area of the Triangle is " << base * height * .5 << "\n\n";            }
            else
            {
                cout << "Invalid Input!!";
            }
            break;
        }
    cout << "1. Calculate the Area of a Circle:\n2. Calculate the Area of a Rectangle:\n3. Calculate the Area of a Triangle:";
    cout << "\n4. Quit:\n\nEnter your choice (1-4):";
    cin >> x;
    }
    }
    return 0;
}
Lines 13 - 15 ask you the first time.

Then, once you enter the switch control structure, you provide input.
Then, you break out of the switch control structure.
Then, lines 62 - 64 ask you again.
yeah that's what I want to happen, but I'm stuck in "case 2:" and it asks the question in there repeatedly instead of breaking and displaying the menu again.
wow, my bracket was in the wrong place
Topic archived. No new replies allowed.