Qbasicnews.com
September 28, 2021, 02:13:19 PM
 Pages: [1]
azagthothe
New Member

Posts: 2

 « on: June 22, 2006, 05:11:05 PM »

I am trying to create an array to store string values for 12 days.  I then want to ask the user how many days they would like to purchase items for and display the items for each of the days up to the number inputed.

here is what i have so far.  any help would be greatly appreciated.

Code:

DIM n AS INTEGER
DIM day AS INTEGER

DIM items\$(12)
items\$(1) = "Partridge in a pear tree"
items\$(2) = "Turtledove"
items\$(3) = "French hen"
items\$(4) = "Calling bird"
items\$(5) = "Gold ring"
items\$(6) = "Geese-a-laying"
items\$(7) = "Swan-a-swimming"
items\$(8) = "Maid-a-milking"
items\$(10) = "Lord-a-leaping"
items\$(11) = "Piper piping"
items\$(12) = "Drummer drumming"

CLS
1 PRINT "Enter amount of item to buy": INPUT day
IF day < 1 THEN
PRINT "Surely you can afford 1 day!"
SLEEP 7
GOTO 1
ELSEIF day > 12 THEN
PRINT "Don't be greedy!"
SLEEP 7
GOTO 1
END IF

FOR n = 1 TO day
PRINT items\$
n = n + 1
NEXT

END
 Logged
Ralph
Ancient Guru

Posts: 544

 « Reply #1 on: June 22, 2006, 05:30:27 PM »

As far as I can see, you've done a good job.  Except for the last:
Code:

FOR n = 1 TO day
PRINT items\$
n = n + 1
NEXT

which should be:
Code:

FOR n = 1 TO day
PRINT items\$(n)
NEXT
 Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Anonymous
Guest
 « Reply #2 on: June 22, 2006, 09:09:23 PM »

To clarify:

FOR... NEXT automatically counts up for every loop iteration. Theres also a command called STEP for it, which works like this

Code:
FOR p = 1 TO 7 STEP 2
PRINT p

NEXT p

This prints 1, 3, 5, 7. So if you don't specify a STEP, it is assumed to be 1 =)
 Logged
 Pages: [1]