nested - JustBasic,在代码中出现“错误的嵌套错误选择/案例”
问题描述
对编程很陌生,如果是基本问题,抱歉,第一次做模块化工作。不知道我在这里做错了什么,但是第 41 行([ShowBalance] --> Case"C" 当我尝试运行我的程序时在标题中吐出错误。什么嵌套不正确?
Balance=1000
Print "Banking Menu"
Do
Gosub[Menu]
Gosub[Deposit]
Gosub[Withdrawal]
Gosub[ShowBalance]
Loop Until Choice$="Q"
Print "Thanks for using the Banking Application"
End
[Menu]
Print "A. Deposit"
Print "B. Withdrawal"
Print "C. Show Balance"
Print "Q. Quit"
Input "Make Selection: ";Choice$
Select Case Upper$(Choice$)
Return
[Deposit]
Case "A"
Input "Enter Amount to Deposit: ";Dep
If Dep > 0 Then
Balance=Balance+Dep
Else
Print "Invalid Amount"
End If
Return
[Withdrawal]
Case "B"
Input "Enter Amount to Withdraw: ";Wdrw
If Wdrw <= 1000 Then
Balance=Balance-Wdrw
Else
Print "Invalid Amount"
Return
[ShowBalance]
Case "C"
Print
Print "*********************************"
Print "*** Account Balance: $";using("####.##",Balance);" ***"
Print "*********************************"
End Select
Print
Print "----------------------------"
Return
解决方案
Case
指令属于Select Case
指令。他们不能分开!您的程序必须始终尊重下面的布局而不干预Return
指令。
Select Case <expression>
Case <values>
<action>
Case <values>
<action>
Case <values>
<action>
End Select
没有子程序的解决方案
您将执行操作的指令直接插入相应Case
指令的下方。缺点是,如果动作块中的指令数量增加,您将失去对整个Select Case
构造的跟踪。
Balance=1000
Print "Banking Menu"
Do
Gosub[Menu]
Loop Until Choice$="Q"
Print "Thanks for using the Banking Application"
End
[Menu]
Print "A. Deposit"
Print "B. Withdrawal"
Print "C. Show Balance"
Print "Q. Quit"
Input "Make Selection: ";Choice$
Select Case Upper$(Choice$)
Case "A"
Input "Enter Amount to Deposit: ";Dep
If Dep > 0 Then
Balance=Balance+Dep
Else
Print "Invalid Amount"
End If
Case "B"
Input "Enter Amount to Withdraw: ";Wdrw
If Wdrw <= 1000 Then
Balance=Balance-Wdrw
Else
Print "Invalid Amount"
End If
Case "C"
Print
Print "*********************************"
Print "*** Account Balance: $";using("####.##",Balance);" ***"
Print "*********************************"
Print
Print "----------------------------"
End Select
Return
使用子程序Deposit、Withdrawal和ShowBalance的解决方案
您将执行操作的指令放在单独的子程序中,并在相应指令的Gosub
正下方插入一个。Case
优点是,即使操作块中的指令数量增加,您也可以清楚地了解整个Select Case
结构。
Balance=1000
Print "Banking Menu"
Do
Gosub[Menu]
Loop Until Choice$="Q"
Print "Thanks for using the Banking Application"
End
[Menu]
Print "A. Deposit"
Print "B. Withdrawal"
Print "C. Show Balance"
Print "Q. Quit"
Input "Make Selection: ";Choice$
Select Case Upper$(Choice$)
Case "A"
Gosub[Deposit]
Case "B"
Gosub[Withdrawal]
Case "C"
Gosub[ShowBalance]
End Select
Return
[Deposit]
Input "Enter Amount to Deposit: ";Dep
If Dep > 0 Then
Balance=Balance+Dep
Else
Print "Invalid Amount"
End If
Return
[Withdrawal]
Input "Enter Amount to Withdraw: ";Wdrw
If Wdrw <= 1000 Then
Balance=Balance-Wdrw
Else
Print "Invalid Amount"
End If
Return
[ShowBalance]
Print
Print "*********************************"
Print "*** Account Balance: $";using("####.##",Balance);" ***"
Print "*********************************"
Print
Print "----------------------------"
Return
推荐阅读
- django - 停止 Celery 缓存 Django 模板
- reactjs - 使用 Redux-toolkit 的 Jest 测试组件,“Store 没有有效的 reducer”
- node.js - 在 vue 组件中使用 Worker 输出
- android - 无法将最新的 Kodein 版本添加到 KMM 项目
- c# - 使用实体框架按日期选择每个组中的一个
- python - pandas 数据框中 YYYYMMDDHHMMSS 的日期
- powershell - PowerShell - 喷溅中的 NoNewLine 写入主机参数
- c++ - 在 C++ 中将成员初始化为 NULL
- unity3d - 如何在 Unity 中替换层次结构中的某些内容?
- keras - 如何在 keras 自定义模型中使用 scklearn RandomForestRegressor 模型?