Please Help Me With My Slot Machine Code

First of all, my code is very broken and I know but I really need help with the balance part of my code. The code below is just for you to get an idea Its not my current version but I am lost on how I am supposed to set up my balance part of the code. I need to be able to add and subtract from it and have it stay the same even when I rerun display.In my case how would I use the new balance after they bet? Any help would be very nice.

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
//allows user to interact with the program
#include <iostream>
using namespace std;

int GenerateNum();		//Prototype for the function GenararteNum()
//pre:
//post: Will return an int value between 0 and 10
int GenerateNum()		//Definition for the function GenarateNum()
{
	//variable declaration to store RandomValue
	int RandomValue;
	//creates a random number below 10
	RandomValue = rand() % 11;
	//returns a random number

	return RandomValue;
}

string NumToFruit();
//pre:
//pre:
string NumToFruit()
{

	if(GenerateNum() == 0)
	{
		return "Apple";
	}
		else if(GenerateNum() == 1)
		{
			return "Banana";
		}
			else if(GenerateNum() == 2)
			{
			return "Grape";
			}
				else if(GenerateNum() == 3)
				{
				return "Orange";
				}

				else if(GenerateNum() == 4)
				{
					return "Kiwi";
				}
					else if(GenerateNum() == 5)
					{
						return "Starfruit";
					}
				else if(GenerateNum() == 6)
				{
					return "Cherries";
				}
			else if(GenerateNum() == 7)
			{
				return "Strawberries";
			}
		else if(GenerateNum() == 8)
		{
			return "Watermelon";
		}
	else
	{
		return "Mango";
	}
}

int AreSame(string, string, string);
//pre:
//post:
int AreSame(string FruitOne, string FruitTwo, string FruitThree)
{

	if(FruitOne == FruitTwo && FruitTwo == FruitThree)
	{
		return "1";
	}
	else if(FruitOne == "Starfruit" && FruitTwo == FruitOne && FruitOne == FruitThree)
	{
		return "2";
	}
	else
	{
		return "0";
	}
}
void DisplaySlots(string, string, string, int, int);
//pre:
//post:
void DisplaySlots(string FruitOne, string FruitTwo, string FruitThree, int Balance, int Win)
{
	cout << "  " << NumToFruit() << "  " << NumToFruit() << "  " << NumToFruit() << endl;
	cout << "->" << FruitOne << "  " << FruitTwo << "  " << FruitThree << endl;
	cout << "  " << NumToFruit() << "  " << NumToFruit() << "  " << NumToFruit() << endl;

	if(Win == 1)
	{
		cout << "You Won!!! Your new balance is: " << Balance << endl;
	}
	else if(Win == 2)
	{
		cout << "You Lucky Duck!! You Hit The Jackpot! Your New Balance Is " << Balance << endl;
	}
	else
	{
		cout << "Your balance is: " << Balance << endl;
	}
}

int BetAndCalculator(int, int);
//pre:
//post:
int BetAndCalculator(int Result, int Balance)
{
	int Bet, Win;

	cout << "Your balance is: " << Balance << endl;
	cout << "How much would you like to bet? ";
	cin >> Bet;

	Balance = Balance - Bet;
	
	if(Result == 1)
	{
		Win = Bet * 4;
		Balance = Balance + Win;
	}
		else if(Result == 2)
		{
			Win = Bet * 100;
			Balance = Balance + Win;
		}
	else
	{
		
	}
		
	return Balance;
}

void Run(int);
//pre:
//post:
void Run(int NewBalance)
{
	char RunAgain;
	int Result, Balance = 1000;
	string FruitOne, FruitTwo, FruitThree;

	FruitOne = NumToFruit();
	FruitTwo = NumToFruit();
	FruitThree = NumToFruit();
	do
	{
	Result = AreSame(FruitOne, FruitTwo, FruitThree);
	BetAndCalculator(Result, Balance);
	DisplaySlots(FruitOne, FruitTwo, FruitThree, Balance, Result);

	cout << "Would you like to spin again? (y/n)";
	cin >> RunAgain;
	}while(RunAgain == 'y');

	cout << "You have selected to quit" << endl;
}
int main()			//start of execution
{
	srand(time(NULL));	//initialize random seed

	Run(NewBalance);

	return 0;
}                    					//end of execution
Last edited on
Topic archived. No new replies allowed.