My program isn't looping

I've stared at this forever, and I can't figure out why it isn't looping. Everything works fine, except it isn't looping. Maybe it's that I've been staring at it too long, and I need a new eye and keep overlooking it.

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


	int randa = 100;
	int randb = 100;
	int money = rand()%randb+randa;


int highlow ()
{
	{
		 
			srand((unsigned)time(0));
			int num = rand()%10;
			int num2 = rand()%10;
			int highlowbet;
			string HLguess;
			int payoff = 1;
			cout<<"\nHIGH-LOW. The computer will generate a random number between 0 and 10. Choose whether or not the next number will be higher or lower than the first one.\n"
				<<"I would like to bet $";
			cin>>highlowbet;
	//invalid entry
			if (highlowbet < 1 || highlowbet > money)
			{
					cout<<"You can't bet that. Try again. What is your bet? $";
						cin>>highlowbet; }

			cout<<"The first number is "<<num<<". Think the number is higher or lower than "<<num<<"?\n";
			cin>>HLguess;

				if (HLguess == "higher" && num < num2){
					cout<<"You're right! It was higher.";
					cout<<"The number was "<<num2<<".\n--------------------\n\n";
					money = money + payoff*highlowbet;
					return(money);	system("PAUSE");

				}
				else if (HLguess == "higher" && num > num2){
					cout<<"You're wrong. It was lower.";
					cout<<"The number was "<<num2<<".\n--------------------\n\n";
					money = money - highlowbet;
					
					return(money);system("PAUSE");
				}
				else if (HLguess == "lower" && num < num2){
					cout<<"You're wrong. It was higher.";
					cout<<"The number was "<<num2<<".\n--------------------\n\n";
					money = money - highlowbet;
					
					return(money);system("PAUSE");
				}
				else if (HLguess == "lower" && num > num2){
					cout<<"You're right! It was lower.";
					cout<<"The number was "<<num2<<".\n--------------------\n\n";
					money = money + payoff*highlowbet;
					
					return(money);system("PAUSE");
				}
				
				return(money);system("PAUSE");
		}

}

int roulette ()
{
	cout<<"roulette";
	return(2);
}

int blackjack ()
{
	cout<<"blackjack";
	return(3);
}

int slots()
{
	cout<<"slots";
	return(4);
}








int main()
{

	srand((unsigned)time(0));
	money = rand()%randb+randa;


	cout<<"Welcome to the Eiselen Casino!\n\nYou have $"<<money<<" to gamble with.\n\nYou can play High-Low, Roulette, Blackjack, or Slots. You may play for how ever long you would like as long as you do not bust. \nGood luck!\n\n";
	
	int choice;		
	do {
	


	cout<<"Please choose which game you would like to play:\n"
		<<"1) High low\n"
		<<"2) Roulette\n"
		<<"3) Blackjack\n"
		<<"4) Slots\n"
		<<"5) I want to leave\n\n";
	cin>>choice;
	
	
switch (choice)
{
case 1:
		
		if (choice == 1) {
		int h;
		h = highlow();
		h;
		cout<<"You now have $"<<h;
		system("PAUSE");
		break;
		}
case 2:

		if (choice == 2){
		int r;
		r = roulette();
		r;
		cout<<"You now have $"<<r; 
				system("PAUSE");break;
		} 

case 3:
		if (choice == 3){
		int b;
		b = blackjack();
		b;
		cout<<"You now have $"<<b;
		system("PAUSE");break;
		} 

case 4:

		if (choice == 4) {
		int s;
		s = slots();
		s;
		cout<<"You now have $"<<s;
		system("PAUSE");break;
		} 

case 5:

		if (choice == 5){
		cout<<"hi"; 
		system("PAUSE");break;
		
		} 
		}
} while (money < 0);
	cout<<"You're bankrupt!";
	return (0);
	}


Lend a quick hand?
while (money < 0);
Do the game while they're bankrupt? xD
I've got the rest of the program written up, so all the elements work, minus having it loop.. someone please help lol.. this is due in a few hours..

This is what my main function looks like

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
int main()
{

	srand((unsigned)time(0));
	money = rand()%randb+randa;


	cout<<"Welcome to the Eiselen Casino!\n\nYou have $"<<money<<" to gamble with.\n\nYou can play High-Low, Roulette, Blackjack, or Slots. You may play for how ever long you would like as long as you do not bust. \nGood luck!\n\n";
	
	int choice;		
	do {
	


	cout<<"Please choose which game you would like to play:\n"
		<<"1) High low\n"
		<<"2) Roulette\n"
		<<"3) Blackjack\n"
		<<"4) Slots\n"
		<<"5) I want to leave\n\n";
	cin>>choice;
	
	
switch (choice)
{
case 1:
		
	if (choice == 1) {
		int h;
		h = highlow();
		h;
		cout<<"You now have $"<<h;
		system("PAUSE");
		break;}
		
case 2:

	if (choice == 2){
		int r;
		r =	roulette();
		r;
		cout<<"You now have $"<<r; 
				system("PAUSE");break;
	}

case 3:
	if (choice == 3){
		int b;
		b = blackjack();
		b;
		cout<<"You now have $"<<b;
		system("PAUSE");break;
	}

case 4:

	if (choice == 4) {
		int s;
		s = slots();
		s;
		cout<<"You now have $"<<s;
		system("PAUSE");break;
	}

case 5:

	if (choice == 5){
		return 0;break;
	}
		}
} while (choice == 5);
	return (0);
	system("PAUSE");
	}
closed account (S6k9GNh0)
LOL, this due in a few hours eh?

Common ways to figure this is out is to simply use debugging techniques. For small problems and programs like these, a simple cout statement or printf statement or even cerr redirected to a log file or the console would do just fine.

Do simple things like print choice variable after it's been set to the said input. Because choice is most likely not 5, the loop will fail for whatever reason.

Also, code like
1
2
3
int s;
s = slots();
s;
is EXTREMELY bad practice. This could be easily optimized and made more readable by doing int s = slots();. That and s; in your code is a waste of CPU since it does absolutely nothing.
Last edited on
Ohhh dang, you're my life-saver. Thank you so much :):)
Topic archived. No new replies allowed.