Slot machines

Hello. (This is my first post so bear with me) I'm trying to make a program with slot machines and I'm having problems. I want to have the user pick an amount of quarters between 1 and 1000. Also, I input different numbers of quarters and the amount the slot machines have been played and it always displays the same number for the amount of times she played. All help is appreciated and thank you for your time.
The original problem statement is:

Martha takes a jar of quarters to the casino with the intention of becoming rich. She plays three machines in turn. Unknown to her, the machines are entirely predictable. Each play costs one quarter. The first machine pays 30 quarters every 35th time it is played; the second machine pays 60 quarters every 100th time it is played; the third pays 9 quarters every 10th time it is played.
Your program should take as input the number of quarters in Martha's jar (there will be at least one and fewer than 1000), and the number of times each machine has been played since it last paid.
Your program should output the number of times Martha plays until she goes broke.


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
#include <cstdlib>
#include <iostream>

using namespace std;

int main ()
{
   int int_jar;
   int int_playcounter;
   int int_turn1;
   int int_turn2;
   int int_turn3;

 cout << "How many quarters are in Martha's jar?" << endl; // Takes the number of quarters in Martha's jar before she starts to play
 cin >> int_jar; // User's choice of number of quarters
 cout << "How many times has the first machine been played since last payout?" << endl; // number of times slot machine one has been played since last payout
 cin >> int_turn1; // User's choice of number of times played since last payout
 cout << "How many times has the second machine been played since last payout?" << endl; // number of times slot machine two has been played since last payout 
 cin >> int_turn2; // User's choice of number of times played since last payout
 cout << "How many times has the third machine been played since last payout?" << endl; // number of times slot machine three has been played since last payout 
cin >> int_turn3; // User's choice of number of times played since last payout

 while (int_jar=1>1000)
 {
   int_turn1 ++;
   int_playcounter ++;
   if (int_turn1==35) // Gets payed every 35 times
   {
    int_jar+=30; // Pays 30 quarters
   }
   int_turn2 ++;
   int_playcounter ++;
   if (int_turn2==100) // Gets payed every 100 times
   {
    int_jar+=60; // Pays 60 quarters
   }
   int_turn3 ++;
   int_playcounter ++;
   if (int_turn3==10) // Gets payed every 10 times
   {
    int_jar+=9; // Pays 9 quarters
   }
 }
   cout << "Martha plays " << int_playcounter << " times before going broke. "; // Displays how many times Martha played

system("PAUSE");
return 0;
}
Last edited on
Well firstly I think you want an error-check that the user-input int_jar value is valid, then modify the while loop to do the right thing:

1
2
3
4
5
6
7
8
9
10
11
if( (int_jar < 1) ||( int_jar > 1000) )
{
   // Quit the program
}
else
{
   while ( int_jar > 0 )
   {
      // Gamble
   }
}


And you current while loop will continue forever, because int_jar never decreases...
line 22: while should not be capitalized.

line 22: (int_jar=1>1000) That expression makes no sense. It tests if 1 is > 1000, the assigns the result (false) to int_jar.

line 25,30,35: if is not capitalized.

line 40: system is not capitalized.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
I was typing this all on my phone but in the original code, while, if, etc...is not capitalized. Spell check just made it that way. Though, I went back and made the changes you suggested. I hope this has made it easier for you and others to read.
Thanks for adding code tags.

That's a lot of code to type in on a phone. Never considered someone would type in that much code on a phone.

Line 23 (my ref to line 22) still doesn't make sense.

So what problems are you having at this point?



I was desperate to fix and finish this code because I just don't know what's wrong with it and others I've asked can't seem to figure it out either. It's also not on my own computer so I had to take a picture of it and type it on my phone.
Well if you take what I have already, the code takes the number of quarters the user has chosen and sets that as the starting amount that is in the jar. I want that number to be between 1 and 1000 and for the program to say "invalid amount", or something along those lines, if the amount is below 1 or above 1000.
It then asks the amount of times slot machine 1, slot machine 2, and slot machine 3 have been played since last payout. I enter a number of different sets of three numbers for the three machines and it gives me the same number each time, which I know the number is wrong.
There's a chart that was written up with the program. I'll add it to see if this helps to understand my problems better.

#of coins in the jar: 50

Times machine #1 has been played since last payout: 5

Times machine #2 has been played since last payout: 50

Times machine #3 has been played since last payout: 5

Total #of times played until she is broke: 68

So as one example: Martha has 50 quarters in her jar. Machine 1 has already been played 5 times, machine 2 has been played 50 times and machine 3 has been played 5 times. She played 68 times before she became broke.
Topic archived. No new replies allowed.