# Algorithm problem for slot machine

This topic is 4717 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi I'm using VB6 to create a slot machine. So far it's working well but I have 1 small problem. The slot machine has nine boxes. It pays out if any 3 of these boxes rolls 7. I can't figure out how to check for this. if i use the following it keeps finding the same 7 over 3 times. for i = 0 to 8 if box(i).picture = imaage(7) and box(i).picture = imaage(7)And box(i).picture = imaage(7) Then you win end if next i I am sure this is simple for you long time programers but for a newbie like me it's got me baffeled. I would greatly appreciate some insight. Please use layman's terms. thank you.

##### Share on other sites
Just count how many sevens you've got. Your code only tests for a single box being a 7 (if box i is a 7, then all 3 box(i).picture == imaage(7) are true!)

count = 0for i = 0 to 8   if box(i).picture == imaage(7) Then count = count + 1next iif count >= 3 Then   you winend if

##### Share on other sites
 Good God you have fast typing skills Fruny [lol] And it's in VB code [sad]

Quote:
 Original post by Marzif i use the following it keeps finding the same 7 over 3 times.for i = 0 to 8if box(i).picture = imaage(7) and box(i).picture = imaage(7)And box(i).picture = imaage(7) Thenyou winend ifnext i

Right now this is what's happening:

You start by looping through from 0 - 8
for i = 0 to 8

Howeverm then you check to see if that box's image is 7, to which if it is, then you display that the player has won:
if box(i).picture = imaage(7) and box(i).picture = imaage(7)And box(i).picture = imaage(7) Then you win

So if the first box is a 7, then:
box(i).picture == 7
box(i).picture == 7
box(i).picture == 7

You are checking the same index 3 times.

To solve this, what you need to do is something like this - I don't know VB that well so this is pseudo code:
ctr = 0FOR i 0 to 8if box(i).picture = imaage(7) Thenctr = ctr + 1end ifnext iif ctr > 0 then  you win

Instead you will keep track of the total number of 7's or in this case, just the fact the player rolled one.

##### Share on other sites
Awesome that solved the problem completely. Thank you both.

##### Share on other sites
darn that does let me know when the player has turned up any 3 sevens but I also need to know where they are so I can light up the squares around them.

sorry darn I thought we had it.

##### Share on other sites
i would assume that all the pictures you are drawing have coordaninths (y wouldnt they) so all you have to do is

if box(i).picture == imaage(7) Then count = count + 1

then

box(i).picture = Light_Up_7Box.

i think this is what your asking (i dont know VB but hopefully you can inturpret what i mean

##### Share on other sites
Quote:
 Original post by Marzdarn that does let me know when the player has turned up any 3 sevens but I also need to know where they are so I can light up the squares around them.sorry darn I thought we had it.

If the current box is a 7, you need to increment the count and also light up that box - just do that in one step:

for i = 0 to 8   if box(i).picture == imaage(7) Then       count = count + 1       box(i).picture = 'fill in whatever image index here