keeps on going and going and does not stop

How do I get this to stop looping continuously? Seems like it's the same problem for each selection:
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
#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;
#define LOWERBOUND -999.99
#define UPPERBOUND 999.99
#define LOWFACT 0
#define UPPERFACT 14

char Menu(char menuchoice);

int getInteger(string, int, int);
double getReal(string, double, double);
void doLarger();
double calcLarger(double, double);
void doDivisible();
bool isDivisible(int dividend, int divisor);
void doRange();
double calcRange(double num1, double num2, double num3, double num4);
void doPower();
double calcMtoN(double M, int N);
void doFactorial();
int calcFactorial(int number);

int main()
{
	char choice;

	choice = Menu(choice);  //Call menu function
	
	while(choice != 'Q' && choice != 'q')
	{
		if(choice == 'L' || choice == 'l')
		{
			doLarger();
		}
		else if(choice == 'D' || choice == 'd')
		{
			doDivisible();
		}
		
		else if(choice == 'R' || choice == 'r')
		{
			doRange();
		}
		else if(choice == 'P' || choice == 'p')
		{
			doPower();
		}
		else 
		{
			doFactorial();
		}	 
				
	}
			
return 0;
}

//*****************************************************************************************************************************************
int getInteger(string prompt, int lowerBound, int upperBound)
{
	int userValue;
	
	cout << prompt << "(" << lowerBound << "-" << upperBound << ")";
	cin >> userValue;
	while(userValue < lowerBound || userValue > upperBound)
	{
		cout << userValue << " is invalid. The value must be between " << lowerBound << "and" << upperBound << ". Try again: ";
		cin >> userValue;
	}	 
	return userValue;
}
	
double getReal(string prompt, double lowerBound, double upperBound)
{
	double userValue;
	
	cout << prompt << "(" << lowerBound << "-" << upperBound << ")";
	cin >> userValue;
	while(userValue < lowerBound || userValue > upperBound)
	{
		cout << userValue << " is invalid. The value must be between " << lowerBound << "and" << upperBound << ". Try again: ";
		cin >> userValue;
	}
	return userValue;
}

void doLarger()
{
	double num1, num2, largernum;
	
	num1 = getReal("Enter the first real value: ", -999.99, 999.99);
	num2 = getReal("Enter the second real value: ", -999.99, 999.99);
	
	largernum = calcLarger(num1, num2);
	cout << "The largest number is: " << largernum << "." << endl;
}	 	 	 

double calcLarger(double num1, double num2)
{
	double max;
	
	if (num1 < num2)
	 {
		 max = num2;
		 cout << endl;
		 cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << max << " is the larger number";  //the second number the user inputs will be shown on the screen here
 	 }
	else 
	 { 
	 	 max = num1;
		 cout << endl;
		 cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << max << " is the larger number";  //the first number the user inputs will be shown on the screen here
	 }
}

void doDivisible()
{
	int num1, num2;
	bool vertict;
	
	num1 = getInteger("Enter the first real value: ", -100.00, 100.00);
	num2 = getInteger("Enter the second real vale: ", -100.00, 100.00);
	
}	 
//****************************************************************************	  
	
bool isDivisible(int dividend, int divisor)
{
	if (dividend % divisor)
	{
	cout << endl;
	cout << dividend << " IS NOT divisible by " << divisor;    //will appear when two numbers the user inputs are not divisible by each other
	}
	else 
	{
	cout << endl;
	cout << dividend << " IS divisible by " << divisor;     //will appear when two numbers the user inputs are divisible by each other
	}
	
}	 
//**************************************************************************
void doRange()
{
	double num1, num2, num3, num4, range;
	
	num1 = getReal("Enter the first real value: ", -100.00, 100.00);
	num2 = getReal("Enter the second real value: ", -100.00, 100.00);
	num3 = getReal("Enter the third real value: ", -100.00, 100.00);
	num4 = getReal("Enter the fourth real value: ", -100.00, 100.00);
	
	range = calcRange(num1, num2, num3, num4);
	
	cout << "The range is: " << range << "." << endl;
}

//***************************************************************************	 	 
double calcRange(double num1, double num2, double num3, double num4)
{
	double numlarge, nummin, range;
	
}

//*******************************************************************************
void doPower()
{ 
	double num1, value;
	int num2;
	
	num1 = getReal("Enter the value of M", 1.00, 100.00);
	num2 = getInteger("Enter the value of N",1, 100);
	
	value = calcMtoN(num1, num2);
	
	cout << num1 << " to the power of " << num2 << "is" << value << endl << endl;
}
//************************************************************************************
double calcMtoN(double M, int N)
{
	int i;
	double num3 = 1.0;
	
	for (i=1; i <= N; i += 1)
	{
		num3 += M;
	}
	
	return num3;
}
//*************************************************************************************
void doFactorial()
{
	int num, fact;
	num = getInteger("Enter a number: ", LOWFACT, UPPERFACT);
	
	fact = calcFactorial(num);
	
	cout << "The factorial of " << num << "is" << fact << endl << endl;
}
//******************************
int calcFactorial(int number)
{
	int i, h;
	
	for(h=1; i <= number; i++)
	{
		h *= i;
	}
	
	return h;
}
//******************************************						  
		
char Menu(char menuchoice)
{
	cout << "Make a selction from the list below." << endl                          //user makes a selction from the following menu
		 << "\nL) Determine the 'L'arger of 2 real numbers" << endl
	  	 << "D) Check if an integer is 'D'ivisible by another integer" << endl
		 << "R) Find the 'R'ange of a set of 4 real numbers" << endl
		 << "P) Find the value of the expression, M to the Nth 'P'ower" << endl
		 << "F) Find the value of a 'F'actorial"<< endl
		 << "\nQ) 'Q'uit" << endl
		 << "\nWhat would you like to do? ";
	cin >> menuchoice;
	
	while (menuchoice != 'l' && menuchoice != 'L' && menuchoice != 'd' && menuchoice != 'D' && 
		   menuchoice != 'r' && menuchoice != 'R' && menuchoice != 'p' && menuchoice != 'P' && 
		   menuchoice != 'f' && menuchoice != 'F' && menuchoice != 'q' && menuchoice != 'Q')
	{
		cout << "***** INVALID SELECTION *** Choose again from (L, D, R, P, F, or Q): " ;      //user has to rechoose a letter until they pick one from the menu
		cin >> menuchoice;
	}	 
}	 

Last edited on
Which loop??
well maybe it's not looping but it keeps going on and on and on and the program does not stop after lets say I chose P and I entered my values. Then it keeps asking for me to enter another number under the same choice. Happens to all of them..
yes, but which loops specifically? Line numbers, please?
I believe its the stuff after return 0. I'm thinking it might be the voids since the choice keeps popping up asking me to "enter a value". Sorry about not being specific enough.
I think you'd have an easier time with do-while loops.
Someone told me what the problem is. "TThe problem with your program is that the Menu function isn't written correctly. You have:

char Menu(char menuchoice);

as your function header, which tells the compiler that the Menu function takes an argument. In this assignment, it should not be passed an argument. It should be:

char Menu();

and the function header should be:

char Menu()

The menuchoice that you are using in the function should be declared inside of the function, just like you would declare a variable inside main() when you want to use it in there. Then at the end of the Menu function, you need to return the value that menuchoice is holding.

Once you make this change to the Menu function, that will change your calling statement in main. You currently have:

choice = Menu(choice);

it will now be:

choice = Menu();

The other problem is that you have to have a second call to the Menu function at the bottom of the while loop in main. You still have to follow the priming/secondary read pattern that we've talked about in lecture. The first call to Menu that is outside of the loop is the priming read. The one at the bottom of the loop will the secondary read."

I have it to:
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
#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;
#define LOWERBOUND -999.99
#define UPPERBOUND 999.99
#define LOWFACT 0
#define UPPERFACT 14

char Menu();

int getInteger(string, int, int);
double getReal(string, double, double);
void doLarger();
double calcLarger(double, double);
void doDivisible();
bool isDivisible(int dividend, int divisor);
void doRange();
double calcRange(double num1, double num2, double num3, double num4);
void doPower();
double calcMtoN(double M, int N);
void doFactorial();
int calcFactorial(int number);

int main()
{
	char choice;

	choice = Menu();  //Call menu function
	
	while(choice != 'Q' && choice != 'q')
	{
		if(choice == 'L' || choice == 'l')
		{
			doLarger();
		}
		else if(choice == 'D' || choice == 'd')
		{
			doDivisible();
		}
		
		else if(choice == 'R' || choice == 'r')
		{
			doRange();
		}
		else if(choice == 'P' || choice == 'p')
		{
			doPower();
		}
		else 
		{
			doFactorial();
		}	 
				
	}
	
	choice = Menu();
			
return 0;
}

//*****************************************************************************************************************************************
int getInteger(string prompt, int lowerBound, int upperBound)
{
	int userValue;
	
	cout << prompt << "(" << lowerBound << "-" << upperBound << ")";
	cin >> userValue;
	while(userValue < lowerBound || userValue > upperBound)
	{
		cout << userValue << " is invalid. The value must be between " << lowerBound << "and" << upperBound << ". Try again: ";
		cin >> userValue;
	}	 
	return userValue;
}
	
double getReal(string prompt, double lowerBound, double upperBound)
{
	double userValue;
	
	cout << prompt << "(" << lowerBound << "-" << upperBound << ")";
	cin >> userValue;
	while(userValue < lowerBound || userValue > upperBound)
	{
		cout << userValue << " is invalid. The value must be between " << lowerBound << "and" << upperBound << ". Try again: ";
		cin >> userValue;
	}
	return userValue;
}

void doLarger()
{
	double num1, num2, largernum;
	
	num1 = getReal("Enter the first real value: ", LOWERBOUND, UPPERBOUND);
	num2 = getReal("Enter the second real value: ", LOWERBOUND, UPPERBOUND);
	
	largernum = calcLarger(num1, num2);
	cout << "The largest number is: " << largernum << "." << endl;
}	 	 	 

double calcLarger(double num1, double num2)
{
	double max;
	
	if(num1 < num2)
	 {
		 max = num2;
		 cout << endl;
		 cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << max << " is the larger number";  //the second number the user inputs will be shown on the screen here
 	 }
	else 
	 { 
	 	 max = num1;
		 cout << endl;
		 cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << max << " is the larger number";  //the first number the user inputs will be shown on the screen here
	 }
}

void doDivisible()
{
	int num1, num2;
	bool vertict;
	
	num1 = getInteger("Enter the first real value: ", -100.00, 100.00);
	num2 = getInteger("Enter the second real vale: ", -100.00, 100.00);
	
}	 
//****************************************************************************	  
	
bool isDivisible(int dividend, int divisor)
{
	if (dividend % divisor)
	{
	cout << endl;
	cout << dividend << " IS NOT divisible by " << divisor;    //will appear when two numbers the user inputs are not divisible by each other
	}
	else 
	{
	cout << endl;
	cout << dividend << " IS divisible by " << divisor;     //will appear when two numbers the user inputs are divisible by each other
	}
	
}	 
//**************************************************************************
void doRange()
{
	double num1, num2, num3, num4, range;
	
	num1 = getReal("Enter the first real value: ", -100.00, 100.00);
	num2 = getReal("Enter the second real value: ", -100.00, 100.00);
	num3 = getReal("Enter the third real value: ", -100.00, 100.00);
	num4 = getReal("Enter the fourth real value: ", -100.00, 100.00);
	
	range = calcRange(num1, num2, num3, num4);
	
	cout << "The range is: " << range << "." << endl;
}

//***************************************************************************	 	 
double calcRange(double num1, double num2, double num3, double num4)
{
	double numlarge, nummin, range;
	
}

//*******************************************************************************
void doPower()
{ 
	double num1, value;
	int num2;
	
	num1 = getReal("Enter the value of M", 1.00, 100.00);
	num2 = getInteger("Enter the value of N",1, 100);
	
	value = calcMtoN(num1, num2);
	
	cout << num1 << " to the power of " << num2 << "is" << value << endl << endl;
}
//************************************************************************************
double calcMtoN(double M, int N)
{
	int i;
	double num3 = 1.0;
	
	for (i=1; i <= N; i += 1)
	{
		num3 += M;
	}
	
	return num3;
}
//*************************************************************************************
void doFactorial()
{
	int num, fact;
	num = getInteger("Enter a number: ", LOWFACT, UPPERFACT);
	
	fact = calcFactorial(num);
	
	cout << "The factorial of " << num << "is" << fact << endl << endl;
}
//******************************
int calcFactorial(int number)
{
	int i, h;
	
	for(h=1; i <= number; i++)
	{
		h *= i;
	}
	
	return h;
}
//******************************************						  
		
char Menu()
{
	string choice;
	
	cout << "Make a selction from the list below." << endl                          //user makes a selction from the following menu
		 << "\nL) Determine the 'L'arger of 2 real numbers" << endl
	  	 << "D) Check if an integer is 'D'ivisible by another integer" << endl
		 << "R) Find the 'R'ange of a set of 4 real numbers" << endl
		 << "P) Find the value of the expression, M to the Nth 'P'ower" << endl
		 << "F) Find the value of a 'F'actorial"<< endl
		 << "\nQ) 'Q'uit" << endl
		 << "\nWhat would you like to do? ";
	cin >> choice;
	
	while (choice != "l" && choice != "L" && choice != "d" && choice != "D" && 
		   choice != "r" && choice != "R" && choice != "p" && choice != "P" && 
		   choice != "f" && choice != "F" && choice != "q" && choice != "Q")
	{
		cout << "***** INVALID SELECTION *** Choose again from (L, D, R, P, F, or Q): " ;      //user has to rechoose a letter until they pick one from the menu
		cin >> choice;
	}
return choice;	  
}	 


Something still not working right.
never mind. I figured out what was wrong. Thanks for the suggestions though!
What ended up being wrong? I have the same issue with a similar program.
Topic archived. No new replies allowed.