Value not updating when passed back into function

I am working on a problem that simulates a Roulette wheel at a casino spinning. The user enters the starting amount of money, chooses a type of bet, and the amount. (So far, I am using the 'single bet' option for testing). The problem I have noticed is that when I am passing the 'total money' from the 'money remaining' function, back into the 'bet menu' function, it is being set back to the starting amount that the user indicated.

I have tried many different ways to solve this, but can't figure out where I have gone wrong.
I feel like I might need to use a pointer to the address of the updated value?

The dynamic array that I have created is intended to store the amount of the bet for each bet, but this is also not working. I'm sure that these are both extremely trivial problems, but I am unable to figure out exactly where I have gone wrong. Any advice is appreciated! Thank you.

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
  
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

void starting_Money_Verify (long int starting_Money);
void bet_menu (long int *ptr, long int starting_Money);
int take_Bet (long int adjusted_Money, int bet_Amount, int bet_Again);
int money_Remaining (long int total_Money, int bet_Amount);

int _tmain(int argc, _TCHAR* argv[])
{
	/***************************************************************
	*starting_Money cannot be greater than 1,000,000
	*num_Bets cannot exceed 8
	*bet_Amount cannot exceed 500
	***************************************************************/
	long int starting_Money= 0, total_Money = 0, *array_ptr;
	array_ptr = new long int[8];//Dynamic array

	cout << "How much money are you coming to the table with?: $";
	cin >> starting_Money;

	starting_Money_Verify (starting_Money); //Passes the starting_Money to 'starting_Money_Verify' fuction.
	bet_menu(array_ptr, starting_Money); //Passes array_ptr and starting_Money to 'bet_Menu' function.

	delete[] array_ptr; //Delet the dynamic array at the end of the function.
	system("pause");
	return 0;
}

/*******************************************************
*This function is passed into the main function.
*It displays the bet menu list, and takes the bet 
*from the user.
*******************************************************/
void bet_menu ( long int *ptr, long int starting_Money)
{	
	int single_Number, num_bets, bet_Again = 1, choice, bet_Amount = 0, total_Money;
		while ((bet_Again == 1) || (total_Money > 0))
		{
			total_Money = total_Money - bet_Amount;
			money_Remaining (total_Money, bet_Again); //Passes starting_Money and bet_Again into 'money_Remaining' function.

			for (num_bets = 0; num_bets < 8; num_bets++)
			{
				ptr[num_bets] = total_Money;
				cout << "Bet Menu:\n";
				cout << "1: Single Bet \n2: All Red Numbers \n3: All Black Numbers \n4: All Even Numbers \n5: All Odd Numbers \n6: First 12 \n7: Second 12 \n8: Third 12 \n9: First Column \n10: Second Column \n11: Third Column \n0: No bet\n";
				cout << "-------------------------------------------------" << endl << "You have $" <<total_Money << " remaining to bet." << endl <<"Enter a selection for bet " << num_bets << ": ";
				cin >> choice;
	
				switch (choice)//Switch menu layout for betting choices
				{
				case 1 : cout << "You have chosen a single number bet.\n";
						 cout << "What number would you like to bet on? You can bet from 0 - 36: ";
						 cin >> single_Number;

					while ((single_Number < 0) || (single_Number > 36)) 
					{
						cout << "You can only bet on numbers from 0 to 36.\nPlease enter a number from 0 - 36: ";
						cin >> single_Number;
					}
					system ("CLS");

					take_Bet(starting_Money, bet_Amount, bet_Again);

					if (bet_Again == 0)
						goto endloop;
				break;
			
			}
		}
	}
		endloop:;
}

int money_Remaining (long int total_Money, int bet_Amount)
{
	total_Money = total_Money - bet_Amount;
	return total_Money;
}

int take_Bet (long int adjusted_Money, int bet_Amount, int bet_Again)
{
	cout << "Enter the dollar amount you would like to bet: $";
	cin >> bet_Amount;
	money_Remaining (adjusted_Money, bet_Amount);
	system ("CLS");
	cout << adjusted_Money << endl;

	if (adjusted_Money == 0) //Exit the loop sequence if user runs out of money
    {
		cout << "You have no more money to bet! Betting phase ending.\n";
		bet_Again = 0;
		cin.get();
		system ("CLS");
	}
	else if (adjusted_Money < 0)//Exit the loop sequence if user runs out of money
	{
		cout << "You cannot bet more than you have left, your last bet is invalid.\nBetting phase ending.\n";
		bet_Again = 0;
		cin.get();
		system ("CLS");
	}
	return bet_Again, adjusted_Money;
}


I'm nearing the point where I feel like I have written a tangled mess of 'spaghetti-code' and it may be better to just save my main function and the switch, but delete the rest and start over from scratch.
Last edited on
looking at line 45 money_Remaining (total_Money, bet_Again); Your money Remaining function returns an integer value which means you have to assign that value to something total_Money = money_Remaining (total_Money, bet_Again); I'm also thinking bet_Again should be bet_Amount


line 108 return bet_Again, adjusted_Money; You can only return one value. If you wan't to return more than that you would have to use pointers or reference variables
Last edited on
I tried your suggestion for line 45, somewhere the variable 'total money' is being re-adjusted to the 'starting_Money' variable.

I also changed line 108, I made the 'if' and 'else if' include return bet_Again, and the return that is in question now only includes 'adjusted_Money'.

Thank you for these by the way. In your opinion, should I scrap some of my functions and try to redo them?
I got the 'total_Money' variable working!!! Thank you for your help, I had forgotten to pass that variable into the take_bet function. Everything is running smoothy now.

Your help is extremeley appreciated, Yanson.
Topic archived. No new replies allowed.