ethonrails
ethonrails

Reputation: 41

Add, Subtract with Qbasic values

I'm back att Qbasic again after 20 years... I'm trying to have a value changed several times, depending on input. This is a very newbie-app, and I'm sure there's an simple answer but this is rubbing my brain.

I want the CREDIT to change with +10 or -10 and have the CREDIT changed there after. Now if I press B it only subtract -10 one time (result CREDIT 90), it stays at 90. I want CREDIT to change every time, according to my input of choice. Let's say I press B the first time, result is CREDIT 90. After that it goes back to line 101 so that I can choose if I want to B or S again, so if I choose to B again, I want the CREDIT to be 80. It just stays at 90. It's of course the same but add instead if I choose S (result CREDIT 110).

Code:

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

Thanks for any help!

Upvotes: 1

Views: 1044

Answers (4)

ethonrails
ethonrails

Reputation: 41

I did something with your code, thinking it would turn out a supersimple kind of highscore list. I am missing something obvious, since there are no errors, only prints:

highscore: One 0 Two 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

I just don't understand why this not works!?

Upvotes: 1

eoredson
eoredson

Reputation: 1165

I'm not sure what you mean by a high-score, but this code compares highest value input:

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

Upvotes: 0

eoredson
eoredson

Reputation: 1165

Here is an improved menu function for calculating credit:

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

Upvotes: 0

eoredson
eoredson

Reputation: 1165

Code to debit/credit a value: (EDIT: 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

Upvotes: 1

Related Questions