QB array help; TWO PROGRAMS
Posted: Tue Mar 14, 2006 11:29 pm
I'm having problems finding out how to output the sum of the numbers in the array and output all the numbers in the array. So far this is what I have for a program, but not sure where to add in the extra lines of code, and I don't know if I've messed up so far in the code I've written. Any help would be greatly appreciated.
OPTION BASE 1
DIM num(10)
CLS
DO
FOR ii = 1 TO 10
INPUT "Enter an even number between 2 and 20"; num(ii)
IF num(ii)MOD2<>0 THEN
PRINT "Please enter an even number between 2 and 20"; num (ii)
END IF
NEXT ii
ii = 1
DO
ii = ii + 1
LOOP UNTIL (ii>10)
INPUT "Do you want to go again (Y/N)"; resp$
LOOP WHILE UCASE$(resp$) = "Y"
I'm having one other problem with one of my other programs as well. I don't know how to print the index of where in the array the smallest value is located. Same deal as the first, I don't know if I have any other problems in the program so far, and help would be really nice. Here is what I have so far.
OPTION BASE 1
DIM num(8)
CLS
DO
FOR ctr = 1 TO 8
READ num (ctr)
NEXT ctr
FOR ctr1 = 1 TO 8
FOR ctr2 = ctr1 + 1 TO 8
IF num(ctr1)>num(ctr2) THEN
SWAP num(ctr1), num(ctr2)
END IF
NEXT ctr2
NEXT ctr1
PRINT "The smallest number is"; num(ctr1)
INPUT "Would you like to go again (Y/N)"; resp$
LOOP WHILE UCASE$(resp$) = "Y"
DATA 7, 2, 5, 6, 3, 9, 4, 9
OPTION BASE 1
DIM num(10)
CLS
DO
FOR ii = 1 TO 10
INPUT "Enter an even number between 2 and 20"; num(ii)
IF num(ii)MOD2<>0 THEN
PRINT "Please enter an even number between 2 and 20"; num (ii)
END IF
NEXT ii
ii = 1
DO
ii = ii + 1
LOOP UNTIL (ii>10)
INPUT "Do you want to go again (Y/N)"; resp$
LOOP WHILE UCASE$(resp$) = "Y"
I'm having one other problem with one of my other programs as well. I don't know how to print the index of where in the array the smallest value is located. Same deal as the first, I don't know if I have any other problems in the program so far, and help would be really nice. Here is what I have so far.
OPTION BASE 1
DIM num(8)
CLS
DO
FOR ctr = 1 TO 8
READ num (ctr)
NEXT ctr
FOR ctr1 = 1 TO 8
FOR ctr2 = ctr1 + 1 TO 8
IF num(ctr1)>num(ctr2) THEN
SWAP num(ctr1), num(ctr2)
END IF
NEXT ctr2
NEXT ctr1
PRINT "The smallest number is"; num(ctr1)
INPUT "Would you like to go again (Y/N)"; resp$
LOOP WHILE UCASE$(resp$) = "Y"
DATA 7, 2, 5, 6, 3, 9, 4, 9