03-03-2003, 10:52 AM
I'm still stuck on this program. As it is now, it works but there has to be a better way. The part I'm referring to is:
Is this the way it is or is thier a way to make this more simple becasue it just doesn't look right? I've tried probably 30 different ways but I cannot get it. Can I not get the same result somehow using this section?
If I remove the REM from the statement above, it calculates the totalCost by the "num" that the user inputs. I've been trying to find a way for this to give me the whole 12 days no matter what "num" is entered. Is there a way to do this? I would appreciate any assistance. TIA
SeeSpot
Code:
REM Calculate total cost over twelve days
RESTORE
FOR i = 1 TO 12
READ gift$(i), cost(i)
LET n = n + 1
LET price = price + cost(i) * n
LET totalCost = totalCost + price
NEXT i
Is this the way it is or is thier a way to make this more simple becasue it just doesn't look right? I've tried probably 30 different ways but I cannot get it. Can I not get the same result somehow using this section?
Code:
REM Calculate daily cost over days
FOR i = 1 TO num
READ gift$(i), cost(i)
LET day = day + 1
LET dailyCost = dailyCost + cost(i) * day
REM LET totalCost = totalCost + dailyCost
PRINT day; gift$(i)
NEXT i
If I remove the REM from the statement above, it calculates the totalCost by the "num" that the user inputs. I've been trying to find a way for this to give me the whole 12 days no matter what "num" is entered. Is there a way to do this? I would appreciate any assistance. TIA
SeeSpot
Code:
REM The Twelve Days of Christmas
CLS
DIM gift$(1 TO 12), cost(1 TO 12)
DO
INPUT "Enter a day from 1 to 12: ", num$
LET num = VAL(num$)
IF num > 0 OR num <= 12 THEN CLS
LOOP UNTIL num > 0 AND num <= 12
LET day = 0
LET dailyCost = 0
LET totalCost = 0
PRINT "The gifts for day"; num; "are"
REM Calculate daily cost over days
FOR i = 1 TO num
READ gift$(i), cost(i)
LET day = day + 1
LET dailyCost = dailyCost + cost(i) * day
REM LET totalCost = totalCost + dailyCost
PRINT day; gift$(i)
NEXT i
REM Calculate total cost over twelve days
RESTORE
FOR i = 1 TO 12
READ gift$(i), cost(i)
LET n = n + 1
LET price = price + cost(i) * n
LET totalCost = totalCost + price
NEXT i
PRINT USING "Cost:$$##,###.##"; dailyCost
PRINT USING "Total cost for the twelve days:$$##,###.##"; totalCost
REM ---Data: gifts, costs
DATA Partridge in a Pear Tree, 27.50, Turtledoves, 25.00
DATA French Hens, 5.00, Calling Birds, 70.00
DATA Golden Rings, 60.00, Geese-A-Laying, 25.00
DATA Swans-A-Swimming, 1000.00, Maids-A-Milking, 4.25
DATA Ladies dancing, 289.50, Lords-A-Leaping, 292.50
DATA Pipers Piping, 95.75, Drummers Drumming, 95.00
END