Why is my switch infinite?

Write your question here.

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
 #include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    // Declared Variables

    const double PI = 3.141592;
    int radius, base, width, lengthTop, lengthBottom, height, shape;
    char displayMenu(int shape);
    double calcCircleArea(double radius);
    double calcRectangleArea(double width, double height);
    double calcTriangleArea(double base, double height);
    double calcTrapezoidArea(double lengthTop, double lengthBottom, double height);
    double CircleArea;
    double RectangleArea;
    double TrapezoidArea;
    double TriangleArea;

    do {

        // Menu start

        cout << "Shape Menu" << endl;
        cout << "[C]ircle" << endl;
        cout << "[R]ectangle" << endl;
        cout << "[T]riangle" << endl;
        cout << "Tra[p]ezoid" << endl;
        cout << "[Q]uit" << endl;

        // Prompts user for upper case letter of Shape defined in menu

        cout << "Shape (C, R, T, P, or Q)?" << endl;
        cin >> shape;

        // In the case of C run the circle area equation

        switch (shape) {
        case 'c':
        case 'C':

            //Prompt user for Radius
            cout << "Radius? " << endl;
            cin >> radius;

            // Run circle area equation

            CircleArea = PI * radius * radius;

            // Display the area to the user in square units.

            cout << "The area of your shape is " << CircleArea << " square units."
                 << endl;
            break;

        // In the case of R run the rectangle area equation
        case 'r':
        case 'R':

            // Prompt user for the width

            cout << "Width? ";
            cin >> width;

            // Prompt user for the for the length

            cout << "Length? ";
            cin >> height;

            // Run rectangle area equation

            RectangleArea = width * height;

            // Display the area in square units
            cout << "The area of your shape is " << RectangleArea << " square units."
                 << endl;

            break;

        // In the case of T run the triangle area equation
        case 't':
        case 'T':

            // Prompt the user for the base of the triangle

            cout << "Base? ";
            cin >> base;

            // Prompt the user for the height of the triangle

            cout << "Height? ";
            cin >> height;

            TriangleArea = 0.5 * base * height;
            cout << "The area of your shape is " << TriangleArea << " square unit."
                 << endl;

            break;

        // In the case of P run the trapezoid area equation
        case 'p':
        case 'P':

            // Prompt the user for the base of the trapezoid

            cout << "Length of the top? ";
            cin >> lengthTop;

            // Prompt the user for the top of the trapezoid

            cout << "Length of the bottom? ";
            cin >> lengthBottom;

            //Prompt the user for the height of the trapezoid

            cout << "Height? ";
            cin >> height;

            // Run the area equation for the trapezoid

            TrapezoidArea = 0.5 * (lengthBottom + lengthTop) * height;

            // Display the trapezoid area in square units

            cout << "The area of your shape " << TrapezoidArea << " square units."
                 << endl;

            // If the input by the user is wrong and does not meet requirements this text will be displayed

            break;

        case 'q':
        case 'Q':

            // Prompt the user for the base of the triangle

            cout << "Good-bye!" << endl;

            break;

        default:
            cout << shape << " is an invalid menu option, program terminated."
                 << endl; // outputs if user enters wrong variable
        }
    } while (shape != 'Q');
    // End of program
    return 0;
}
@kattykat243

You declared the variable, shape, to be an int, but you're search for a char, in your switch statement.
@whitenite1

Omg, so silly. Thank you it works now!
Topic archived. No new replies allowed.