Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Program help please!
#18
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:

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
Reply


Messages In This Thread
Program help please! - by SeeSpot - 03-01-2003, 01:11 AM
Program help please! - by pr0gger - 03-01-2003, 01:37 AM
Program help please! - by SeeSpot - 03-01-2003, 01:52 AM
Program help please! - by pr0gger - 03-01-2003, 02:08 AM
Program help please! - by SeeSpot - 03-01-2003, 10:32 AM
Program help please! - by toonski84 - 03-01-2003, 10:56 AM
Program help please! - by SeeSpot - 03-01-2003, 11:27 AM
Program help please! - by SeeSpot - 03-01-2003, 11:31 AM
Program help please! - by SeeSpot - 03-03-2003, 04:24 AM
Program help please! - by toonski84 - 03-03-2003, 04:51 AM
Program help please! - by SeeSpot - 03-03-2003, 05:06 AM
Program help please! - by toonski84 - 03-03-2003, 05:13 AM
Program help please! - by SeeSpot - 03-03-2003, 05:24 AM
Program help please! - by SeeSpot - 03-03-2003, 05:42 AM
Program help please! - by pr0gger - 03-03-2003, 05:58 AM
Program help please! - by SeeSpot - 03-03-2003, 06:29 AM
That's not a bug... - by Glenn - 03-03-2003, 08:22 AM
Program help please! - by SeeSpot - 03-03-2003, 10:52 AM
Program help please! - by toonski84 - 03-03-2003, 02:50 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)