Hi everyone,
I've been lurking here for a while and absorbing all the information I can find here while learning TI-Basic.
I started making a simple little utility that calculates times and I'm having trouble writing something that will subtract a time duration from a point in time.
I want the program to allow the user to enter a time point (the current time perhaps) in hh:mm:ss and then the user enters a time duration in hh:mm:ss and have the program subtract this duration from that time point and spit out the new time of day. And it needs to take multiple days into account so I could subtract say..72 hours from 12:00 PM
Below is the code I have so far, and it works until you get beyond -1 days. I think it falls apart because that bit of code under the If statement only accounts for 86400(1-day)
I feel like this should be a simple matter of arithmetic but every time I try something new I get weird results and now I'm kind of stumped. Could someone maybe suggest what I'm doing wrong here or what I can I do to make this work? I feel like I missing something very simple here but I can't figure it out.
Below is my code with some comments about what it's doing.
Code:
I've been lurking here for a while and absorbing all the information I can find here while learning TI-Basic.
I started making a simple little utility that calculates times and I'm having trouble writing something that will subtract a time duration from a point in time.
I want the program to allow the user to enter a time point (the current time perhaps) in hh:mm:ss and then the user enters a time duration in hh:mm:ss and have the program subtract this duration from that time point and spit out the new time of day. And it needs to take multiple days into account so I could subtract say..72 hours from 12:00 PM
Below is the code I have so far, and it works until you get beyond -1 days. I think it falls apart because that bit of code under the If statement only accounts for 86400(1-day)
I feel like this should be a simple matter of arithmetic but every time I try something new I get weird results and now I'm kind of stumped. Could someone maybe suggest what I'm doing wrong here or what I can I do to make this work? I feel like I missing something very simple here but I can't figure it out.
Below is my code with some comments about what it's doing.
Code:
ClrHome
Disp "24 CLOCK"
Disp " "
Disp "TIME "
Input "HOUR: ",A
Input "MINUTE: ",B
Input "SECOND: ",C
Disp " "
Disp "SUBTRACT TIME"
Input "HOURS: ",D
Input "MINUTES: ",E
Input "SECONDS: ",F
60A+B→B
60B+C→C
60D+E→E
60E+F→F
C-F→G
//Converts both timevalues into total seconds and then subtracts them and stores the value to G
0→H
//Resets H to 0 in case we don't use the If code below
If G<0
Then
86400-abs(G)→Z
iPart(86400/Z)→H
Z→G
End
//If the new time is in the previous day it subtracts those seconds from G and stores day value in H for display below
iPart(G/3600)→I
G-3600*I→G
iPart(G/60)→J
G-60*J→G
//Turns seconds back into hh:mm:ss format for display below
ClrHome
Disp "Days -",H
Disp "HOUR: ",abs(I)
Disp "MINUTE: ",J
Disp "SECOND: ",G
Pause