20年后,我又回来了qbasic ...我试图根据输入而改变值几次。这是一个非常新手的应用,我敢肯定有一个简单的答案,但这在揉我的大脑。
我希望信用 10或-10更改,并在此之后更改信用。现在,如果我按B下一次仅减去-10一次(结果信用90(,则保持在90。我希望每次都会改变信用,根据我的选择输入。假设我是第一次按B,结果是信用90。之后它返回到第101行,以便我可以选择是否要再次b或s,所以如果我选择再次B或B80.它仅保持在90。当然是相同的,但是如果我选择s(结果信用110(。
。代码:
1
CLS
credit = 100
sell = credit + 10
buy = credit - 10
101
CLS
PRINT " (Q)uit"
PRINT " Your credit: "; credit
PRINT: PRINT
INPUT " (B)uy for 10 or (S)ell for 10"; bs$
bs$ = LCASE$(bs$)
IF bs$ = "b" THEN GOTO 2
IF bs$ = "s" THEN GOTO 3
IF bs$ = "q" THEN END ELSE GOTO 101
2
credit = buy
GOTO 101
3
credit = sell
GOTO 101
感谢您的任何帮助!
借记/信用a值的代码:(编辑:02-12-2018(
REM sample to adjust credit value
credit = 100
buy = 10
sell = 10
DO
PRINT "Your credit: "; credit
PRINT " (B)uy for"; buy; "(S)ell for"; sell; "(Q)uit";
INPUT bs$: bs$ = LCASE$(bs$)
IF bs$ = "b" THEN credit = credit + buy
IF bs$ = "s" THEN credit = credit - sell
IF bs$ = "q" THEN END
LOOP
END
我对您的代码做了一些事情,以为它会结果出现一种高分列表。我缺少明显的东西,因为没有错误,只有打印:
高分:一个0两个0
REM highscore sample for QB64, edit:
' assign variables
one = 1
two = 2
' in this case the players final credit is 25000 = X
X = 25000
' current highscore list (this is values that i want to be saved when app closes)
A = 1234
B = 12
'DO ' i don't think i need do/loop for this, right?
IF X > A THEN X = one
IF X < A THEN X = two
PRINT "highscore:"
PRINT
PRINT "One: "; one ' shouldn't this print "One: 25000"?
PRINT "Two: "; two ' and this "Two: 0"?
END
我只是不明白为什么这不起作用!?
这是一个改进的菜单功能,用于计算信用:
REM sample to adjust credit value (EDIT 02-12-2018 adds history for QB64)
DEFLNG A-Z
credit = 100 ' starting credit
buy = 10 ' amount to add
sell = 10 ' amount to subtract
DO
COLOR 15
PRINT "Your credit: "; credit
COLOR 14
PRINT " (B)uy for"; buy
PRINT " (S)ell for"; sell
PRINT " (H)istory"
COLOR 15
PRINT "Enter(Q to quit)? ";
LOCATE , , 1
DO
_LIMIT 100 ' remove for Qbasic
b$ = INKEY$
IF LEN(b$) THEN
PRINT
EXIT DO
END IF
LOOP
SELECT CASE LCASE$(b$)
CASE "b"
credit = credit + sell
bought = bought + sell
CASE "s"
credit = credit - buy
sold = sold + buy
CASE "h"
COLOR 14
PRINT "Credits bought:"; bought
PRINT "Credits sold:"; sold
COLOR 15
PRINT "Press a key:";
DO
_LIMIT 100 ' remove for Qbasic
x$ = INKEY$
IF LEN(x$) THEN
PRINT
EXIT DO
END IF
LOOP
CASE "q"
COLOR 7
END
END SELECT
LOOP
END
我不确定您的意思是高分,但是此代码比较最高值输入:
REM highscore sample for QB64:
DO
PRINT "Enter value";: INPUT X
IF X = 0 THEN EXIT DO
IF X > V THEN V = X
LOOP
PRINT "The highest value was:"; V
END