' Interactive Menu System — INPUT, SELECT CASE, DO/LOOP menu framework
#COMPILE EXE
#DIM ALL

FUNCTION ShowMenu() AS LONG
    LOCAL choice AS LONG
    PRINT "===== MAIN MENU ====="
    PRINT "1. Display Date/Time Info"
    PRINT "2. Count to N"
    PRINT "3. Show Squares and Cubes"
    PRINT "4. Number Guessing Game"
    PRINT "5. Fibonacci Sequence"
    PRINT "6. Prime Number Check"
    PRINT "7. Exit"
    PRINT "========================================"
    INPUT "Enter your choice (1-7): ", choice
    PRINT
    FUNCTION = choice
END FUNCTION

SUB ShowDateTimeInfo()
    LOCAL t AS LONG
    t = TIMER
    PRINT "Timer value: " & STR$(t) & " ms"
    PRINT "Minutes today: " & STR$(INT(t / 60000))
    PRINT "Seconds today: " & STR$(INT(t / 1000))
    PRINT
END SUB

SUB CountToN()
    LOCAL n AS LONG
    LOCAL i AS LONG
    LOCAL outLine AS STRING
    INPUT "Count up to: ", n
    FOR i = 1 TO n
        IF LEN(outLine) > 0 THEN outLine = outLine & " "
        outLine = outLine & STR$(i)
        IF LEN(outLine) > 70 THEN
            PRINT outLine
            outLine = ""
        END IF
    NEXT i
    IF LEN(outLine) > 0 THEN PRINT outLine
    PRINT "Counted to " & STR$(n)
    PRINT
END SUB

SUB ShowSquaresCubes()
    LOCAL i AS LONG
    LOCAL n AS LONG
    INPUT "Show squares and cubes up to: ", n
    FOR i = 1 TO n
        PRINT STR$(i) & "  " & STR$(i * i) & "  " & STR$(i * i * i)
    NEXT i
    PRINT
END SUB

SUB GuessingGame()
    LOCAL target AS LONG
    LOCAL guess AS LONG
    LOCAL attempts AS LONG
    target = (INT(TIMER) MOD 97) + 1
    attempts = 0
    PRINT "Guess the number (1-97):"
    DO
        INPUT "Your guess: ", guess
        attempts = attempts + 1
        IF guess < target THEN
            PRINT "Too low!"
        ELSEIF guess > target THEN
            PRINT "Too high!"
        END IF
    LOOP UNTIL guess = target
    PRINT "Correct in " & STR$(attempts) & " attempts!"
    PRINT
END SUB

SUB FibonacciSeq()
    LOCAL n AS LONG
    LOCAL i AS LONG
    LOCAL a AS LONG
    LOCAL b AS LONG
    LOCAL c AS LONG
    INPUT "How many Fibonacci numbers: ", n
    a = 0
    b = 1
    FOR i = 1 TO n
        PRINT STR$(a)
        c = a + b
        a = b
        b = c
        IF i MOD 10 = 0 THEN PRINT
    NEXT i
    PRINT
    PRINT
END SUB

SUB PrimeCheck()
    LOCAL n AS LONG
    LOCAL i AS LONG
    LOCAL isPrime AS LONG
    INPUT "Check if prime: ", n
    IF n < 2 THEN
        PRINT STR$(n) & " is not prime."
        EXIT SUB
    END IF
    isPrime = 1
    FOR i = 2 TO INT(SQR(n))
        IF n MOD i = 0 THEN
            isPrime = 0
            EXIT FOR
        END IF
    NEXT i
    IF isPrime THEN
        PRINT STR$(n) & " is PRIME"
    ELSE
        PRINT STR$(n) & " is not prime (by " & STR$(i) & ")"
    END IF
    PRINT
END SUB

FUNCTION PBMAIN() AS LONG
    LOCAL choice AS LONG
    PRINT "========================="
    PRINT " Interactive Menu System "
    PRINT "========================="
    PRINT
    DO
        choice = ShowMenu()
        SELECT CASE choice
            CASE 1
                CALL ShowDateTimeInfo()
            CASE 2
                CALL CountToN()
            CASE 3
                CALL ShowSquaresCubes()
            CASE 4
                CALL GuessingGame()
            CASE 5
                CALL FibonacciSeq()
            CASE 6
                CALL PrimeCheck()
            CASE 7
                PRINT "Goodbye!"
                EXIT LOOP
            CASE ELSE
                PRINT "Invalid choice. Try again."
                PRINT
        END SELECT
    LOOP
    FUNCTION = 0
END FUNCTION
