Skip to content
TheChatArchiveThe Chat Archive
o1-preview-2024-09-12· OpenAIAi2 WildChat-4.8M (AI2)

Write a program in Basic which writes "hello world", waits 5 seconds, writes "goodbye…

  1. User

    Write a program in Basic which writes "hello world", waits 5 seconds, writes "goodbye world" and then closer after 13 seconds.

  2. Assistant

    Certainly! Below is a BASIC program that performs the tasks you've specified:

    PRINT "hello world"
    SLEEP 5
    PRINT "goodbye world"
    SLEEP 13
    END
    

    Explanation:

    • PRINT "hello world" displays the message "hello world" on the screen.
    • SLEEP 5 pauses the program for 5 seconds.
    • PRINT "goodbye world" displays the message "goodbye world" after the pause.
    • SLEEP 13 waits for an additional 13 seconds before closing.
    • END terminates the program.

    Note: The SLEEP command is commonly available in many BASIC interpreters like QBASIC or FreeBASIC. It pauses the program for the specified number of seconds.

    If SLEEP is not available in your BASIC version, you can use a loop with the TIMER function to create the delays:

    PRINT "hello world"
    startTime! = TIMER
    DO WHILE TIMER - startTime! < 5
        ' Wait for 5 seconds
        IF TIMER < startTime! THEN
            ' Handle midnight rollover
            startTime! = startTime! - 86400
        END IF
    LOOP
    
    PRINT "goodbye world"
    startTime! = TIMER
    DO WHILE TIMER - startTime! < 13
        ' Wait for 13 seconds
        IF TIMER < startTime! THEN
            ' Handle midnight rollover
            startTime! = startTime! - 86400
        END IF
    LOOP
    END
    

    In this version:

    • We use TIMER, which returns the number of seconds elapsed since midnight.
    • We capture the start time and loop until the desired number of seconds have passed.
    • The loop includes a check for midnight rollover when TIMER resets to zero.

    Remember to run this code in a BASIC environment that supports these commands.