slot machine

when i win, the money i won, is added, but the bet is not *3 or *5 or *10, and when it loops again, it starts at 1000 again...and,
all 3 random numbers are all the same (if first is 3, then all are 3...)

[EDITED!]
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
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;

int Random(int low, int high)       
{
	int rand_num = low + rand() % ((high + 1) - low );
	return rand_num;
}

int main()
{
	
    int low1(2), low2(2), low3(2);    
	int high1(7), high2(7), high3(7);
	int cash = 1000;
	int num;
	int bet;

	cout << "Player´s chips: $" << cash << endl;

	while (true)    
	{

	cout << "1) Play slot. 2) Exit. ";
	cin >> num;


	if (num == 2)
    {
		cout << "Exiting..." << endl;
		break;
    }

	
	else if (num == 1)  
	{
		cout << "Enter your bet: ";
		cin >> bet;

		if (bet > cash || bet < 0 || bet == cash || bet == 0)    
		{
		cout << "You did not enter a valid bet." << endl;
		}
		
		else
		{      
			srand( time(0) );

			int first = Random(low1, high1);
			int second = Random(low2, high2);
			int third = Random(low3, high3);

			string s1 = "You won!"; 
			
			cout << first << " " << second << " " << third << endl;

			if (first == 7 && second == 7 && third == 7)
			{
				cout << s1 << endl;
				cash += bet * 10;
			}
			else if (first == second == third)
			{
				cout << s1 << endl;
				cash += bet *  5;
			}
			else if (first == second || second == third || first == third)
			{
				cout << s1 << endl;
				cash += bet *  3;
			}
			else
			{
				cout << "You lose!" << endl;
				cash -= bet;
			}

			if (cash < 0)
			{
				cout << "You have no more money left!" << endl;
				cout << "Exiting..." << endl;
			    break;
			}

			cout << "Player´s chips: $" << cash << endl;


		}

	}
	
	else
	{
		cout << "You did not enter a valid number!" << endl;
	}

	}
}


ty in advance!
Last edited on
Try moving your srand(time(0)) to the beginning of main() instead. I think that might be your problem.
it worked :D
ty so much

but there is still one problem:
how do i make it, so when "while" starts to loop again, it stores previously gained money?

and also:
how could i make this part of code more "efficient":

1
2
3
4
5
6
	int low1 = 2; 
	int low2 = 2; 
	int low3 = 2;
	int high1 = 7; 
	int high2 =7; 
	int high3 = 7;  


like maybe so:

1
2
	int low1, low2, low3 = 2; 
	int high1, high2, high3 = 7; 


ive come up with this, but im curious if theres even more efficient way:

 
int low1(2), low2(2), low3(2);


and also if there is a more efficient way to write this:

 
if (first == 7 && second == 7 && third == 7)


PS: ive edited the code above

Last edited on
Have you tried using an array?
int low[3]={3,3,3};
ty :)
Last edited on
No problem. Try reading about them at the tutorial if you have any problems with them, or ask me.
Topic archived. No new replies allowed.