QB array help; TWO PROGRAMS

Discuss whatever you want here--both QB and non-QB related. Anything from the DEF INT command to the meaning of life!

Moderators: Pete, Mods

Post Reply
darquedante
Newbie
Posts: 5
Joined: Fri Mar 10, 2006 7:38 pm

QB array help; TWO PROGRAMS

Post by darquedante »

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
User avatar
Zamaster
Veteran
Posts: 174
Joined: Wed Jun 15, 2005 1:51 pm

Post by Zamaster »

Okay your first bit of code makes hardly any to no sense. Im not sure what you were trying to do... give this a spin:

Code: Select all

CLS
DIM Nums(1 TO 10) AS INTEGER
FOR i% = 1 TO 10
gr$ = " "
DO
inpstr$ = "(" + LTRIM$(STR$(i%)) + ")Gimme a" + gr$ + "number between 2 and 20"
PRINT inpstr$; : INPUT num%
gr$ = " !VALID! "
LOOP UNTIL (num% > 1 AND num% < 23) AND (num% MOD 2 = 0)
gr$ = " "
Nums(i%) = num%
NEXT i%
addr% = 0
FOR i% = 1 TO 10
addr% = addr% + Nums(i%)
PRINT "-"; Nums(i%)
NEXT i%
PRINT "Sum ="; addr%
SYSTEM
Your second program is errr... kinda on the right track..? Try this one:

Code: Select all

CLS
DIM Nums(1 TO 8) AS INTEGER
FOR i% = 1 TO 8: READ Nums(i%): NEXT i%
NLow% = Nums(1): ILow% = 1
FOR i% = 2 TO 8
IF Nums(i%) < NLow% THEN NLow% = Nums(i%): ILow% = i%
NEXT i%
PRINT "In the set of data:"
FOR i% = 1 TO 8: PRINT Nums(i%); : NEXT i%
PRINT CHR$(13) + "The lowest number is:"; NLow% 'or Nums(ILow%) works to
PRINT "The index in which this number is found is:"; ILow%
DATA 7, 2, 5, 6, 3, 9, 4, 9
SYSTEM
I know Im probably doing your homework but... Im a generous guy!
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN
darquedante
Newbie
Posts: 5
Joined: Fri Mar 10, 2006 7:38 pm

Post by darquedante »

Well after about five hours in the computer lab the wife got all of her assignments done, she was just lost in really I'm not sure, I'm a old schoolC64 BASIC user and have touched only off and on since then. I'm trying to get her to take a C# computer course next queater I think with what of the basics of programming she has gained so far with C# she hopfully would go farther, she is though olny taking this course so that we would have something in common, I'm a computer tech and she can play games on the computer and check her e-mail W00t!, so yeah anything to help bridge the gap is nice, thanks for all the help you guys have supplied.
User avatar
Zamaster
Veteran
Posts: 174
Joined: Wed Jun 15, 2005 1:51 pm

Post by Zamaster »

as far as this post goes, *guy
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN
User avatar
Zim
Veteran
Posts: 98
Joined: Mon Dec 05, 2005 4:31 pm
Location: Wisconsin, USA
Contact:

Post by Zim »

If (that's a big IF) you know how many numbers (elements) are in the array, then:

Code: Select all

sum=0
for i=1 to n
  print i, array(i)
  sum=sum+array(i)
next i

print "Total is"sum
will essentially do what you want, that is, to print each of the values in the array, and add them up.
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---
Post Reply