Too Many Repetitive Inputs To Get The Loops To Exit.

Hello! I have written a program that will calculate the area of a circle, rectangle, and a triangle if so chosen by the integers the user inputs (1-4, 4 is quit). Inside of these functions there is a similar menu asking if you would like to quit the program, go back to the main menu, or get another area from the current object (circle, rectangle, or triangle). However, when I enter 1 to quit, it loops the function again, making me have to enter another base/height/radius to move on. Once I have finished this and the menu asking me what I would like to do next pops up (quit, go back to the main menu, or get another area) I press 1 again and it finally exits. The same thing happens when I try to go back to the main menu except it loops the function 5 times (each time I need to have the input of 2 for the menu that pops up). I have been trying to figure out why it takes so many inputs to get out of the functions nOptionOne(), nOptionTwo(), and nOptionThree(), to no avail. Can anybody tell me what is wrong in my code?
Thanks in advance!


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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
 #include <cstdio>
#include <ctime>
#include <cstdlib>
#include <iostream>
#define PI 3.141592653589793238462643383279502884197169399375

using namespace std;
//TRY USING THE NEW WORD TO SOLVE YOUR PROBLEM!!!!!!!!!!!
int main()
{
    void displayProgramExplanation();
    int nOptionOne();
    int nOptionTwo();
    int nOptionThree();
    int nLoopContCon , nLoopContCon2;
    int nLoopContCon3 = 0;
    do
    {
    displayProgramExplanation();
   cout << "1. Calculate the Area of Circle.\n"
        << "2. Calculate the Area of Rectangle.\n"
        << "3. Calculate the Area of Triangle.\n"
        << "4. Quit.\n"
        << "Enter your choice:" << endl;
    int nOption = 0;
    cin >> nOption;
    switch(nOption)
    {
       case 1:
       nOptionOne();
       if(nOptionOne() == 0)
       {
           system("PAUSE");
           return 0;
       }
       else if(nOptionOne() == -1)
       {
           cout << "An error has occured within the program.\n"
           << "The program will now exit. Please retry executing the program.";
           return 0;
       }
       else if (nOptionOne() == 2)
       {
       nLoopContCon = nOptionOne();
       }
       break;

       case 2:
       nOptionTwo();
       if(nOptionTwo() == 0)
       {
           system("PAUSE");
           return 0;
       }
       else if(nOptionTwo() == -1)
       {
          cout << "An error has occured within the program.\n"
           << "The program will now exit. Please retry executing the program.";
           return 0;
       }
       else if (nOptionTwo() == 2)
       {
       nLoopContCon2 = nOptionTwo();
       }
       break;

       case 3:
       nOptionThree();
       if(nOptionThree() == 0)
       {
           system("PAUSE");
           return 0;
       }
       else if(nOptionThree() == -1)
       {
          cout << "An error has occured within the program.\n"
           << "The program will now exit. Please retry executing the program.";
           return 0;
       }
       else if (nOptionThree() == 2)
       {
       nLoopContCon3 = nOptionThree();
       }
       break;

       case 4:
       system("PAUSE");
       return 0;

    }
    } while(nLoopContCon == 2 || nLoopContCon2 == 2 || nLoopContCon3 == 2);


}
void displayProgramExplanation()
{
    cout << "This program calculates four things; the area of a circle, the area of a rectangle,\n and the area of a triangle."
         << "These options are displayed below. Select 1-4 to choose what you would like to do." << endl;
}

int nOptionOne()
{
    int nOptionSelect;
    do
  {
   system("CLS");

   cout << "Please enter the radius of the circle:";
   double dRadius = 0.0;
   cin >> dRadius;
   double dCArea = PI * (dRadius*dRadius);
   cout << "The area of the circle is " << dCArea << endl;
   do{
   cout << "What would you like to do? Choose 1-3.\n"
        << "1. Quit?\n"
        << "2. Go back to the menu?\n"
        << "3. Find another circle's area?";
        cin >> nOptionSelect;


        switch(nOptionSelect)
        {
           case 1:
           return 0;
           break;

           case 2:
           return 2;
           break;

           case 3:
           break;

           default:
           cout << "You didn't enter a valid number. Try again.";
           system("PAUSE");
           break;
           system("CLS");
        }

   }while(nOptionSelect <= 0 && nOptionSelect > 3);

}while(nOptionSelect == 3);
return -1;
}

int nOptionTwo()
{
    int nSecondOS;

    do{
    system("CLS");
   cout << "What is the base of the rectangle?\n";
   double BoR = 0.0;
   cin >> BoR;

   cout << "What is the hieght of the rectangle?\n";
   double HoR = 0.0;
   cin >> HoR;

   double dRArea = BoR * HoR;

   cout << "The area of the rectangle is " << dRArea;
   do{
   cout << "What would you like to do? Choose 1-3.\n"
        << "1. Quit?\n"
        << "2. Go back to the menu?\n"
        << "3. Find another rectangle's area?";
   cin >> nSecondOS;

   switch(nSecondOS)
   {
           case 1:
           return 0;


           case 2:
           return 2;


           case 3:
           break;

           default:
           cout << "You didn't enter a valid number. Try again.";
           system("PAUSE");
           break;
           system("CLS");
    }
    break;
   }while(nSecondOS <= 0 && nSecondOS > 3);
    } while(nSecondOS == 3);
    return -1;
}
int nOptionThree()
{
    int nThirdOS;
    do{
    system("CLS");
   cout << "What is the base of the triangle?\n";
   double dBoT = 0.0;
   cin >> dBoT;

   cout << "What is the hieght of the triangle?\n";
   double dHoT = 0.0;
   cin >> dHoT;

   double dTArea = (dBoT* dHoT) * 0.5;

   cout << "The area of the rectangle is " << dTArea;
   do{
   cout << "What would you like to do? Choose 1-3.\n"
        << "1. Quit?\n"
        << "2. Go back to the menu?\n"
        << "3. Find another rectangle's area?";
   cin >> nThirdOS;

   switch(nThirdOS)
   {
           case 1:
           return 0;


           case 2:
           return 2;


           case 3:
           break;

           default:
           cout << "You didn't enter a valid number. Try again.";
           system("PAUSE");
           break;
           system("CLS");

    }
    break;
   }while(nThirdOS <= 0 && nThirdOS > 3);
    } while(nThirdOS == 3);
    return -1;
}
A couple of things I see.

Here - you do the call the same function twice in a row.

1
2
3
4
5
6
7
    int nOption = 0;
    cin >> nOption;
    switch(nOption)
    {
       case 1:
       nOptionOne();  //<- function is called here, but return value isn't stored anywhere 
       if(nOptionOne() == 0)
//<-function is called again here


This while statement will never be true. A number can't be both less than 0 and greater than 3 at the same time.

}while(nOptionSelect <= 0 && nOptionSelect > 3);
Those mistakes were pretty simple. I am sorry I didn't catch them myself. Thank you so much for your help! I believe my program should run properly now.
Topic archived. No new replies allowed.