1

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!

eoredson
  • 1,167
  • 2
  • 14
  • 29
ethonrails
  • 41
  • 9

4 Answers4

1

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
eoredson
  • 1,167
  • 2
  • 14
  • 29
  • Ahhhh, thanks a lot!! Finally! (I mean, it was a superfast reply, thanks again, I scratched my head for half a day about this...) – ethonrails Feb 12 '18 at 09:08
  • Ok, I figured the keep value out, but alternative ways to do it is welcome. I just changed the GOTO value though, guess it already is kinda simple! – ethonrails Feb 12 '18 at 10:30
1

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!?

eoredson
  • 1,167
  • 2
  • 14
  • 29
ethonrails
  • 41
  • 9
0

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
eoredson
  • 1,167
  • 2
  • 14
  • 29
  • You should look at the QB64 IDE at www.qb64.net – eoredson Feb 13 '18 at 04:42
  • 1
    Ok, I dumped the timer thing, got a better idea to work... kinda got everything like I had in mind, mostly by just trying things out... It still IS a noob-app, but anyway. The only thing left is a highscore list. This I only found kinda complicated code on. Maybe it has to be, but I really need some help here! Maybe I should open a new thread? I haven't really got the rules of Stackoverflow yet. – ethonrails Feb 13 '18 at 12:04
  • The timer thingy is a QB64 specific function that releases time slice to the OS during tight keyboard entry loops. – eoredson Feb 14 '18 at 00:28
  • Ok. Do you have anything on highscore-like example? You don't have to sample me a complete code, understad that might take some time, but do you have any tips on what to use? I only found that one example (don't remember werre now). – ethonrails Feb 14 '18 at 08:12
0

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
eoredson
  • 1,167
  • 2
  • 14
  • 29
  • 1
    Thanks huge for the code, I actually got some flashbacks... I mean a score list were the remembered, say, 10 highest scores (and names) get kept even when app is closed. Don't know if I this is how it was, but you do need to keep this kind of information in a separate file, right..? (please; how do you format code in comments?!) – ethonrails Feb 15 '18 at 10:51
  • I can't write code for you, only answer questions concerning specific code you have already written and are having problems with. You must post the code in question in a separate question. – eoredson Feb 15 '18 at 22:16
  • 1
    I understand, thanks for all the help though! I'm going to give it some more time on my own, don't want to waste peoples time with what I believe is something very obvious... – ethonrails Feb 16 '18 at 08:27