0

I'm trying to create simple slot machine with three slots. Each slot will generate a random number between 0 and 9 inclusive. The user will start with 1,000 coins and can wager any number of coins per slot pull. The payouts are: if 2 slots equal each other the user wins 10x the wager, if 3 slots equal each other the user wins 100x the wager, and if 0 slots equal the user loses the wagers. I want the output to generally look like this:

Slot Machine
You have 1000 coins.
Press 0 to exit, any other number to play that many coins per spin
1000
Spin: 4 6 6
You won 10000 coins! You now have 11000 coins.
Press 0 to exit, any other number to play that many coins per spin
11000
Spin: 4 4 1
You won 110000 coins! You now have 121000 coins.
Press 0 to exit, any other number to play that many coins per spin
121000
Spin: 5 1 9
You lost 121000 coins! You now have 0 coins.
Press 0 to exit, any other number to play that many coins per spin
10
You ran out of coins. Thanks for playing.

I'm not very familiar with programming and a few of the seniors I look after would enjoy this for a little fun with them learning how to use a computer. Thanks.

Mary
  • 149
  • 2
  • 5
  • 11

1 Answers1

0

Something like this (pseudocode). Add appropriate print statements, error checking, etc.

coins = 1000

while (coins > 0)
{
     input wager
     if wager > coins
         wager = coins
     if wager <= 0
         exit

     slot1 = rand(0..9)
     slot2 = rand(0..9)
     slot3 = rand(0..9)

     if (slot1 == slot2 and slot2 == slot3)
         coins = coins + (100 * wager)
     else if (slot1 == slot2 or slot2 == slot3 or slot1 == slot3)
         coins = coins + (10 * wager)
     else
         coins = coins - wager
}

You're broke ... sorry
John
  • 15,990
  • 10
  • 70
  • 110
  • Thank you. That's along the lines of what I was thinking. I'll try to work out something like that. – Mary Feb 13 '11 at 02:02