1

我正在用 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'
4

2 回答 2

2

你没有关闭你的 if 语句。

IF-
ELSEIF
ELSE
END IF

在关闭您的潜艇之前关闭您的 IF 语句。

于 2013-08-21T22:19:27.497 回答
1

阅读您的代码有点困难;您可能希望在将来粘贴之前正确缩进。:)

无论如何,您的问题在于您的语法。在每个 ELSE 语句及其对应的代码之后,您需要放置一个 END IF。

请参阅http://www.picaxe.com/BASIC-Commands/Program-Flow-Control/if/以更好地理解这一点。

于 2013-08-21T22:22:04.380 回答