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?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293`` ``````#include #include #include 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:
 ``1234567`` ``````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:
 ``12345678910111213141516171819202122`` ``````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.