Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Running Totals
#1
I am sending you a program which I have started to constuct. It is for
recording by Bike Training on
I cannot seem to make a Running Total of the Kilometers Rided Can you help
me

CLS
OPEN "Record.rec" FOR APPEND AS #1
CLS
PRINT "Cycling Record"
PRINT "type END to quit"
PRINT

DO WHILE (day$ <> "END")
INPUT "Date ", day$
IF (day$ <> "END") THEN
INPUT "Kilometres ", Kms
INPUT "Minutes", min
Speed = Kms / (min / 60)
WRITE #1, day$, Kms, min, Speed
END IF
PRINT
LOOP
CLOSE #1
INPUT "Press Enter to see the Total Record", dummy
CLS
OPEN "Record.rec" FOR INPUT AS #1
PRINT "Date Kms Mins Av.Speed "
PRINT "---------------------------------"

tmp$ = "\ \ ### ### ####.# "

DO WHILE (NOT EOF(1))
INPUT #1, day$, Kms, min, Speed
PRINT USING tmp$; day$; Kms; min; Speed
LOOP
CLOSE #1
Reply
#2
Perhaps replacing:
Code:
WRITE #1, day$, Kms, min, Speed
by:
Code:
PRINT #1, day$ + STR$(Kms) + STR$(min) + STR$(Speed)
Helps.

You'll thus get this:
Code:
CLS
OPEN "Record.rec" FOR APPEND AS #1
   CLS
   PRINT "Cycling Record"
   PRINT "type END to quit"
   PRINT

   DO WHILE (day$ <> "END")
      INPUT "Date ", day$
      IF (day$ <> "END") THEN
         INPUT "Kilometres ", Kms!
         INPUT "Minutes", min!
         Speed! = Kms! / (min! / 60.0)
         PRINT #1, day$ + STR$(Kms!) + STR$(min!) + STR$(Speed!)
      END IF
      PRINT
   LOOP
CLOSE #1

INPUT "Press Enter to see the Total Record", dummy

CLS
OPEN "Record.rec" FOR INPUT AS #1
   PRINT "Date Kms Mins Av.Speed "
   PRINT "---------------------------------"

   tmp$ = "\ \ ### ### ####.# "

   WHILE NOT EOF(1)
      INPUT #1, day$, Kms!, min!, Speed!
      PRINT USING tmp$; day$; Kms!; min!; Speed!
   WEND
CLOSE #1

I've not used PRINT USING so much, so I can't predict if there's a mistake in the mask you set in tmp$. But according to me, this should work.
Reply
#3
You can keep the data entry part as it is, but modify the result printing part like this:

Code:
OPEN "Record.rec" FOR INPUT AS #1
PRINT "Date Kms Mins Av.Speed "
PRINT "---------------------------------"

tmp$ = "\ \ ### ### ####.# "
tmp2$ = "\ \ ### ### ####.#  in Total"

DO  
TotKms=0:totMin=0
DO
IF EOF(1) THEN GOTO finish
INPUT #1, day$, Kms, min, Speed
PRINT USING tmp$; day$; Kms; min; Speed  
IF day$=oldday$ THEN
totkms=totkms+kms
totmin=totmin+min
ELSE
day$=oldday$
EXIT DO
ENDIF
LOOP
PRINT USING tmp2$; day$; TotKms; Totmin; TotKms*60/Totmin
PRINT
LOOP
finish:
CLOSE #1
I have written it directly on the reply window, it may have some error...
Antoni
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)