none
Clock function help! RRS feed

  • Question

  • So I have looked EVERYWHERE and can find very little help having to do with the clock and its functions. I am brand new to Small Basic, so I'm sure I'm doing more than just trying to add hours to the clock wrong. I desperately need help!

    Here is the assignment description:

    "SMALL BASIC EXERCISE 2

    The company you work for just opened two
    new branches. One is in New York City, the other in
    London. They need a very simple program to find out
    if the branches are open or closed based on the
    current time of the Headquarters here in Portland.
    The hours of both branches are 9:00 a.m.-9:00 p.m. in
    their own time zone.

    HERE IS YOUR ASSIGNMENT: Create a
    program that will determine whether the London
    and New York offices are open or closed based on
    the current time of the HQ in Portland. Have the
    program display if each of the two branches are
    open or closed.
    Hints: Clock.Time class (Clock.Hour operates
    on a 24-hour clock)
    If statements"

    Based on my previous assignments, I'm trying to plug in bits of code that I've already learned to use and here is what I've come up with:

    TextWindow.WriteLine("Hello! Your current time is:" +Clock.Time+) 

    TextWindow.WriteLine("Which station are you inquiring about? Please enter NYC, or London. Input:")
    Input=TextWindow.Read()

    LT()
    Sub LT
      LT=Clock.Hour +8
      EndSub
    Sub NT 
        NT=Clock.Hour +3
      EndSub
      
    'station
    Sub station
      If (Input="London") then  
     Program="program1"
    ElseIf (Input ="NYC") then 
     Program="program2"
    Endif
    EndSub
      
    ' program1
    Sub program1  
      If (LT >= 2100 And LT <=0859) Then
      TextWindow.WriteLine("The London Station is closed.")
      ElseIf (LT >= 0900 and LT <=2059) Then
      TextWindow.WriteLine("The London Station is open.")
      EndIf 
    EndSub

    'program2
    Sub program2
    If (NT >= 2100) Then
      TextWindow.WriteLine("The New York Station is closed.")
      ElseIf (NT >= 0900) Then
      TextWindow.WriteLine("The New York Station is open.")
    EndIf  
    EndSub

    Please help if you can! This is driving me nuts! I don't know if I'm making this a lot more complicated than it needs to be, or if it's just gone over my head.

    Saturday, November 25, 2017 12:17 PM

Answers

  • You have put nerly all of your program in subroutines, but you only call the sub LT().

    Do you understand the use of subroutines?  If you change the first part of your program (after Input) to:

    LT=(Clock.Hour +8)*100  '' needed to make the right comparisons
    NT=(Clock.Hour +3)*100
    If (Input="London") then  
      program1()
    ElseIf (Input ="NYC") then 
      program2()
    Endif
    Then you will get further.  Other errors to repair yourself:  remove the last + in the first line

    Also in program1  LT cannot be greater then 2100 and at the same time smaller then 859.


    Jan [ WhTurner ] The Netherlands


    Saturday, November 25, 2017 1:38 PM
    Answerer

All replies

  • You have put nerly all of your program in subroutines, but you only call the sub LT().

    Do you understand the use of subroutines?  If you change the first part of your program (after Input) to:

    LT=(Clock.Hour +8)*100  '' needed to make the right comparisons
    NT=(Clock.Hour +3)*100
    If (Input="London") then  
      program1()
    ElseIf (Input ="NYC") then 
      program2()
    Endif
    Then you will get further.  Other errors to repair yourself:  remove the last + in the first line

    Also in program1  LT cannot be greater then 2100 and at the same time smaller then 859.


    Jan [ WhTurner ] The Netherlands


    Saturday, November 25, 2017 1:38 PM
    Answerer
  • Agh! I totally meant to call NT out, too. I was really getting flustered with this. I'm sorry for that. Again, I'm very new to this, so I'm still trying to figure out the use of sub-routines. Like, when they're convenient and when they're a hinderence.

    Thank you so much for the help!


    Coding N00b. Please be kind!

    Thursday, November 30, 2017 5:33 AM
  • What did you eventually get for your final answer for this problem? I'm currently trying to work on this as well, and I cant seem to figure it out. 

    Thanks!

    Wednesday, February 21, 2018 12:58 AM
  • Please give the part of the program which is not working. Then I can help you.

    Jan [ WhTurner ] The Netherlands

    Wednesday, February 21, 2018 11:53 AM
    Answerer
  • I'm taking the same course now and also struggled with this question.

    This is my final result. 

    TextWindow.Writeline("This will check to see if the New York and London Branch are currently open.")
    TextWindow.Pause()
    Program.Delay(1000)
    NY_hour = (Clock.Hour + 3)*100
    London_hour = (Clock.Hour + 8)*100
    minutes = Clock.Minute
    New_york = (NY_hour + minutes)
    London = (London_hour + minutes)
    TextWindow.WriteLine("The current local time is:" + Clock.time) 
    If(New_york > 2100)Then
      TextWindow.WriteLine("The New York Branch is Closed.")
      ElseIf(New_york > 900)Then
        TextWindow.WriteLine("The New York Branch is Open.")
    EndIf 
    If(London > 2100 Or London < 900)Then
      TextWindow.WriteLine("The London Branch is Closed.")
      ElseIf(London > 900 Or London < 2100)Then
        TextWindow.WriteLine("The London Branch is Open.")
    EndIf


    • Edited by Sterner123 Friday, June 15, 2018 6:42 PM type-o
    Friday, June 15, 2018 1:32 PM
  • Hello Sterner123, 

    You have an error in the line   London = (London + minutes)

    It should be   London = (London_hour + minutes)


    Jan [ WhTurner ] The Netherlands

    Friday, June 15, 2018 3:23 PM
    Answerer