RegularJacob
RegularJacob

Reputation: 11

Printing input statements to a specific row(?)

Doing a project for a qbasic class, and i need the 1st row to ask for input i.e. " Enter projected depletion rate: ", after doing that it will run a loop under it, wherein i need it to print another input statement on that same 1st row, " Enter another projected depletion rate or 0 to quit :" the issue i'm having is that if i use LOCATE it will print the next results of the loop directly under that statement when id like it to print below the last results in the list, at the lowest unused space, and it doesn't clear the top row of old text. I know part of it is that the LOCATE is getting repeated because of the loop but i'm genuinely stuck. sorry for format i'm new :)

    CLS

DIM percent AS DOUBLE
DIM ozLevel AS DOUBLE
DIM counter AS INTEGER
DIM change AS DOUBLE

INPUT "enter a projected depletion rate, or 0 to quit: ", percent

PRINT
PRINT TAB(2); "Loss"; TAB(17); "Final Ozone"
PRINT TAB(2); "Rate"; TAB(10); "Years"; TAB(17); "Concentration"

change = (percent / 100)

DO WHILE percent <> 0

counter = 0
ozLevel = 450
    DO UNTIL ozLevel < 200
    counter = counter + 1
    ozLevel = ozLevel - (ozLevel * change)
    LOOP
PRINT USING "##.##%"; TAB(2); percent;
PRINT TAB(10); counter;
PRINT USING "###.##"; TAB(17); ozLevel;
LOCATE 1, 1
INPUT "enter new projection: ", percent
change = (percent / 100)
LOOP

LOCATE 1, 35
PRINT "DONE"

END

Upvotes: 1

Views: 81

Answers (1)

Sep Roland
Sep Roland

Reputation: 39191

QBasic has the CRSLIN function that tells you where the cursor is.

  • Make sure that printing the 3rd result does a carriage return and linefeed. Just remove the ;

  • Now store the index to the next available row in a suitable variable like TableRow.

  • Input as before on the 1st row of the screen.

  • Position the cursor on the next available row using this variable after each following input.

    ...
    PRINT USING "###.##"; TAB(17); ozLevel
    tablerow = CRSLIN
    LOCATE 1, 1
    INPUT "enter new projection: ", percent
    change = (percent / 100)
    LOCATE tablerow, 1
    LOOP
    ...

Upvotes: 1

Related Questions