我做错了怎么这么困惑?

时间:2013-08-21 22:16:40

标签: compiler-errors basic

我正在BASIC制作一个程序,我知道它真的很糟糕,我可以修复很多东西,但我想知道的是为什么我收到错误来结束潜艇?

' 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'

2 个答案:

答案 0 :(得分:2)

您没有关闭if语句。

IF-
ELSEIF
ELSE
END IF

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

答案 1 :(得分:1)

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

无论如何,你的问题在于你的语法。在每个ELSE语句及其相应的代码之后,您需要输入END IF。

有关此问题的详情,请参阅http://www.picaxe.com/BASIC-Commands/Program-Flow-Control/if/