Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

lotto number matching

Status
Not open for further replies.

veevee

Programmer
Dec 12, 2000
15
CA
I've started a program where the user keys in the six winning weekly lottery numbers
and tests them for a match with their numbers (same each week). As indicated below,
my first statement tests for a match of all six (jackpot) and the second statement
tests for no matches at all. I don't know how to continue, or if this the best
way to start. There is a second, third and fourth prize for 5, 4, and 3 prizes respectively.

// test for a jackpot
on (release) {
if (a == 09 && b == 13 && c == 17 && d == 26 && e == 37 && f == 40) {
gotoAndStop ("jackpot");
}
}
// test for no numbers at all
on (release) {
if (a != 09 && b != 13 && c != 17 && d != 26 && e != 37 && f != 40) {
gotoAndStop ("zilch");
}
}
 
hi

seems like the best way to do this would be combining an array with a function to check each value in the array. I'll come back and have a look tomorrow, unless someone has posted already in the meantime.

dave

(gone to zzzzzz)
dave@pinkzeppelin.com

^^^^^^^^^^^^^^^^^^^^^​
 
Hmmm.... Something like (and please bear in mind that this is first thing in the morning after a heavy night)...


matchingNums=0;

for (i=0;i<6;i++) {
for (j=0;j<6;j++) {
if (myLottoNums == lottoNums[j]) {
matchingNums++;
}
}
}

if (matchingNums == 6) { gotoAndStop(&quot;jackpot&quot;) };
if (matchingNums == 0) { gotoAndStop(&quot;zilch&quot;) };




This looks about right (I think - can't quite think at the moment if the for loop should be <5, but I think <6 is OK); the variables are as follows:

myLottoNums is an array of your lottery numbers.
lottoNums is an array of this weeks lottery numbers.
matchingNums shows you how many of your lotto numbers match.
i is used to count through the myLottoNums array.
j is used to count through the lottoNums array.

You could quite easily convert this into a nice little function if you felt so inclined!

=)

PetitPal.

p.s. Wouldn't it be useful if Macromedia put a case statement into flash (hint hint).
 
Darn... appologies for the bad italics, forgot that TGML stuff would catch as italics! Here it is again...

thematchingNums=0;

for (i=0;i<6;i++) {
for (j=0;j<6;j++) {
if (myLottoNums == lottoNums[j]) {
matchingNums++;
}
}
}

if (matchingNums == 6) { gotoAndStop(&quot;jackpot&quot;) };
if (matchingNums == 0) { gotoAndStop(&quot;zilch&quot;) };

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top