none
Time Comparison RRS feed

  • Question

  • I'm a new user with version 0.9.  The last time I tried programming, it was in middle school on a TI-83+ and the farthest I got was with If-then-else sequences.  

     

    Here, I'm trying to do the same thing, but have the computer compare the time with what the user says it is.  The code is as follows:

     

    start:
    TextWindow.WriteLine("What time is it?")
    T = TextWindow.Read() 
    If (t = Clock.Time) Then
     TextWindow.WriteLine("Holy ____, I need to get going. Toodles!")
    Else 
     TextWindow.WriteLine("Liar. That's not what my watch says.")
     Goto start
    EndIf 
     

    The problem with this code is that any time a user imputs will be met with a negative because either A) the time won't ever perfectly sync or B) I'm having the user input it in an incorrect method. I'd appreciate suggestions as to removing the seconds and AM/PM modifiers, or to change how the user's input is translated by the computer.

    Friday, June 18, 2010 6:41 PM

Answers

  • The user has to enter in the correct format and be correct to the nearest second, e.g. Clock.Time returns a string something like '19:52:45'.  It is unlikely the user will be exactly correct.  Perhaps something like the following:

    start:
    TextWindow.WriteLine("What time is it?")
    TextWindow.WriteLine("Use the format for example 20:03")
    T = TextWindow.Read()
    time = Text.GetSubText(Clock.Time,1,5) 'Just hours (24 clock) and minutes (00 to 59)
    If (t = time) Then
     TextWindow.WriteLine("Holy ____, I need to get going. Toodles!")
    Else
     TextWindow.WriteLine("Liar. That's not what my watch says.")
     Goto start
    EndIf

    Friday, June 18, 2010 7:00 PM
    Moderator