Help with Adding this all up

So I just took out the parts of the code that were relevant below, the entire code is too long. Above the main are the functions being used.
Here is my problem: I can drop chips into slots plenty of times with correct results of where the chip is landing. But, for myWinnings, It only displays wherever the last chip was and gives me that amount of money. Basically I need to accumlate and add the sum of each drop. So if I drop a chip 50 times, I should have 50 winnings and then add them all to get the TOTAL. I just couldn't figure it out. Any tips, pointers, ideas?

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


void mySlotSimulator(double selection)//this displays where the chip goes
{
	double randomizer;
	srand(time(0));  //seed the random number
for(int i=1; i<=12; i++ ) //12 iterations 
{
  randomizer = rand() % 2;
  
  if (randomizer == 0)
  {
	  
	selection += ( selection == 8  ) ?  -0.5 : 0.5;
  } 
  else
  {
	selection += ( selection == 0  ) ?  0.5 : -0.5;
  }
  
  cout << selection << endl; //print out the 12 drops of a chip
 
}
}


double myWinnings(double selection)//how much $$$ i win
{
	double user_winnings = 0;
if (selection == 0){
	user_winnings = 100;
}
if (selection == 1){
	user_winnings = 500;
}
if (selection == 2){
	user_winnings = 1000;
}
if (selection == 3){
	user_winnings = 0;
}
if (selection == 4){
	user_winnings = 10000;
}
if (selection == 5){
	user_winnings = 0;
}
if (selection == 6){
	user_winnings = 1000;
}
if (selection == 7){
	user_winnings = 500;
}
if (selection == 8){
	user_winnings = 100;
}

return user_winnings;
}

int main()
{

cout << "\n How many chips would you like to play?"<<"\n";
cin >> multiple_chips;

if(multiple_chips < 0)//don't allow negative numbers
{
	break;
}

cout << "\n Which Slots would you like to Drop the chip(s) into(Please enter a slot #0-8)?"<<"\n";
cin >> selection_two;

if((selection_two < 0) || (selection_two > 8))//only allow 0-8 as option or return to menu
{
	break;
}

for (int s=1; s<=multiple_chips; s++) //this is where I need help or in functions above
{
	mySlotSimulator(selection_two);
	myWinnings(selection_two);
}

cout<<"You've won  a total of $" << myWinnings(selection_two) << "!" << endl;	
cout<<"You averaged winnings of $" << myWinnings(selection_two)/multiple_chips << " a chip."<< endl;
}
return 0;
I need help adding things up too.
That was a terrific post.
You will want to declare a variable to store the total winnings in. The function myWinnings returns the winnings for a single chip, so you can add the result of that function to the total winnings for every chip.

There may be another problem too. Notice that the function mySlotSimulator is given the value of selection_two, but selection_two is not modified within mySlotSimulator. Then, myWinnings is given the value of selection_two which is the same even after the chip has dropped. You may want to return the value of selection at the end of mySlotSimulator. Then you would input the return value of mySlotSimulator into myWinnings to get the winnings for a single chip.

For example:
1
2
3
4
5
6
7
double totalWinnings = 0;
double finalChipPosition;

for (int s=1; s<=multiple_chips; s++) {
    finalChipPosition = mySlotSimulator(selection_two);
    totalWinnings += myWinnings(finalChipPosition);
}
man I suck. I can't get myWinnings to work. I can't get around
There may be another problem too. Notice that the function mySlotSimulator is given the value of selection_two, but selection_two is not modified within mySlotSimulator. Then, myWinnings is given the value of selection_two which is the same even after the chip has dropped.
You may want to return the value of selection at the end of mySlotSimulator.

For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
double mySlotSimulator(double selection)//this displays where the chip goes
{
    double randomizer;
    srand(time(0));  //seed the random number
    for(int i=1; i<=12; i++ ) //12 iterations 
    {
        randomizer = rand() % 2;
  
        if (randomizer == 0)
        {
            selection += ( selection == 8  ) ?  -0.5 : 0.5;
        } 
        else
        {
            selection += ( selection == 0  ) ?  0.5 : -0.5;
        }
  
        cout << selection << endl; //print out the 12 drops of a chip
    }

    return selection;
}


I may be interpreting your code incorrectly, but it seems like the user should select an input for mySlotSimulator, then the result of the simulation determines their winnings. With your original code, the user's input determined the winnings. Does that make sense? Correct me if I'm wrong, it's your code >_O.
Last edited on
Topic archived. No new replies allowed.