Qbasicnews.com
April 09, 2020, 06:11:41 PM
 Pages: [1]
 Author Topic: can't compare each set of numbers between two arrays  (Read 1304 times)
janed
New Member

Posts: 5

 « on: October 24, 2004, 07:24:34 PM »

I would appreciate help on this. I'm stuck

What I'm trying to do is record the number of "hits" or matches, in order,
between two sets of numbers.
The first set is always in numerical order 1,2,3,4,5,6
The second set is a set of non-repeating random numbers. It can be a larger
range, say 1 through 9.

Example:
1,2,3,4,5,6 (first set)  1 through 6
1,4,8,3,5,7 (second set) random number drawn. 1 through 9 (non-repeating
i.e. each must all be different from all the others)

The program should spit out "2" as the result. Because there are two
matches.
1-1  match
2-4 no match
3-8 no match
4-3 no match
5-5 match
6-7 no match

Below is what I got so far but I can't get the program to compare one from
set 1 against one from set 2.

Thanks

CLS
CONST itema = 6         'number of draws per game. Allows upto to 200
maximum
DIM a(itema)
match=0

cntr = 0
FOR num = 1 TO itema
LET a(num) = num
NEXT num
PRINT : PRINT "initial draw:";

FOR num = 1 TO itema
PRINT a(num);
NEXT num

REM ####################################################################

CONST itemb = itema
DIM b(itemb)

RANDOMIZE TIMER      ' must be outside loop
50

FOR numb = 1 TO itemb
LET b(numb) = INT(9 * RND) + 1
NEXT numb

REM    ############### prevents duplicate random numbers #################
FOR OUTER = 1 TO itemb - 1
FOR INNER = OUTER + 1 TO itemb
IF b(OUTER) < b(INNER) THEN GOTO NOCHANGE
IF b(OUTER) = b(INNER) THEN GOTO 50    ' prevents duplicate numbers
'    SWAP b(OUTER), b(INNER)   ' rem out. Do not want to sort random
numbers
NOCHANGE:
NEXT INNER
NEXT OUTER
REM    ##############################################################

PRINT : PRINT "random draw:";
FOR numb = 1 TO itema
PRINT b(numb);

NEXT numb

PRINT : PRINT "number of matches is "; match
 Logged
Plasma
Na_th_an

Posts: 1770

 « Reply #1 on: October 24, 2004, 09:21:30 PM »

Code:
match = 0
FOR i = 1 TO itema
IF a(i) = b(i) THEN match = match + 1
NEXT
 Logged
 Pages: [1]