【问题标题】:What am I doing wrong so confused?我做错了什么如此困惑?
【发布时间】:2013-08-21 22:16:39
【问题描述】:

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

【问题讨论】:

    标签: compiler-errors basic


    【解决方案1】:

    你没有关闭你的 if 语句。

    IF-
    ELSEIF
    ELSE
    END IF
    

    在关闭你的 subs 之前关闭你的 IF 语句。

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

      • 抱歉给您带来的不便,我之前只使用过一次这个网站,非常感谢
      • 没问题。只是想下次我会把它扔在那里。 :)
      猜你喜欢
      • 1970-01-01
      • 2011-04-13
      • 2021-08-10
      • 1970-01-01
      • 2010-12-03
      • 2011-06-01
      • 1970-01-01
      • 2012-07-18
      • 1970-01-01
      相关资源
      最近更新 更多