我正在用 BASIC 制作一个程序,我知道它真的很糟糕,我可以修复很多东西,但我想知道的是为什么我在结束 subs 时会出错?
' simple calculator
declare sub main
declare sub add
declare sub subtract
declare sub multiply
declare sub divide
declare sub question
declare sub sendBack 'asks to send user back to main menu
main
sub main 'Where the user makes there selection
dim choice as integer
input "Welcome, would you like to 1.Add 2.Subtract 3.Multiply 4.Divide" ; choice
if choice = 1 then
add
elseif choice = 2 then
subtract
elseif choice = 3 then
multiply
elseif choice = 4 then
divide
else
print "Error 404 your choice does not exist, please enter a corresponding number!"
main
end sub
sub question 'Get 2 integers from user
dim num1 as integer
dim num2 as integer
input "Please enter your first number" ; num1
input "Please enter your second number" ; num 2
end sub
sub add
question
print num1 + num2
end sub
sub subtract
question
print num1 - num2
end sub
sub multiply
question
print num1 * num2
end sub
sub divide
question
print num1 / num2
end sub
sub sendBack
dim answer
input "Would you like to make another calculation, 1.Yes, 2.No" ; answer
if input = 1 then
main
elseif input = 2
sleep
else
print "Please enter a valid choice, thankyou!"
sleep
end sub
我得到的错误
C:\Users\Harjit\Documents\Coding (Basic)\calculator.bas(30) error 32: Expected 'END IF', found 'end' in 'end sub'
C:\Users\Harjit\Documents\Coding (Basic)\calculator.bas(34) error 60: Illegal inside functions, found 'sub' in 'sub question 'Get 2 integers from user'
C:\Users\Harjit\Documents\Coding (Basic)\calculator.bas(46) error 60: Illegal inside functions, found 'sub' in 'sub add'
C:\Users\Harjit\Documents\Coding (Basic)\calculator.bas(55) error 60: Illegal inside functions, found 'sub' in 'sub subtract'
C:\Users\Harjit\Documents\Coding (Basic)\calculator.bas(64) error 60: Illegal inside functions, found 'sub' in 'sub multiply'
C:\Users\Harjit\Documents\Coding (Basic)\calculator.bas(73) error 60: Illegal inside functions, found 'sub' in 'sub divide'
C:\Users\Harjit\Documents\Coding (Basic)\calculator.bas(82) error 60: Illegal inside functions, found 'sub' in 'sub sendBack'
C:\Users\Harjit\Documents\Coding (Basic)\calculator.bas(96) error 32: Expected 'END IF' in 'end sub'