PIMPBOT5000
Member
Not sure if this is the right place or not, but I noticed in software, programming and games it was mostly help on using it not creating it.
How do you share a variable inside of a subroutine with its main module in QBasic?
I know how to do it the other way around by declaring the variable as COMMON SHARED, but I can't figure out how to share it to the main module.
Here is my subroutine for solving a quadratic equation...
--------------------
SUB QUADEQ
2 RESTORE
PRINT
PRINT "For the form (ax"; CHR$(253); " + bx + c = 0) enter a, b, and c in the following prompts"
PRINT
INPUT " a: ", a
PRINT
INPUT " b: ", b
PRINT
INPUT " c: ", c
LET disc = (b ^ 2) - 4 * a * c
SELECT CASE disc
CASE IS < 0
LET real = -b / (2 * a)
LET imag = SQR(-disc) / (2 * a)
PRINT
PRINT
PRINT USING "The answer is ##i and ##i"; real + imag; real - imag
CASE IS > 0
LET x1 = (-b + SQR(disc)) / (2 * a)
LET x2 = (-b - SQR(disc)) / (2 * a)
PRINT
PRINT
PRINT USING "The answer is ## and ##"; x1; x2
CASE IS = 0
LET x = -b / (2 * a)
PRINT
PRINT
PRINT USING "The answer is ##"; x
END SELECT
PRINT
PRINT
33 INPUT "Would you like to try again (Y/N)"; choice$
SELECT CASE choice$
CASE "y", "Y"
GOTO 2
CASE "n", "N"
SYSTEM
CASE ELSE
GOTO 33
END SELECT
END SUB
--------------------
I want to share choice$ with the main module so I can use it's value to dump the user back to the main interface screen with an IF.... THEN.... statement.
Any ideas?
How do you share a variable inside of a subroutine with its main module in QBasic?
I know how to do it the other way around by declaring the variable as COMMON SHARED, but I can't figure out how to share it to the main module.
Here is my subroutine for solving a quadratic equation...
--------------------
SUB QUADEQ
2 RESTORE
PRINT "For the form (ax"; CHR$(253); " + bx + c = 0) enter a, b, and c in the following prompts"
INPUT " a: ", a
INPUT " b: ", b
INPUT " c: ", c
LET disc = (b ^ 2) - 4 * a * c
SELECT CASE disc
CASE IS < 0
LET real = -b / (2 * a)
LET imag = SQR(-disc) / (2 * a)
PRINT USING "The answer is ##i and ##i"; real + imag; real - imag
CASE IS > 0
LET x1 = (-b + SQR(disc)) / (2 * a)
LET x2 = (-b - SQR(disc)) / (2 * a)
PRINT USING "The answer is ## and ##"; x1; x2
CASE IS = 0
LET x = -b / (2 * a)
PRINT USING "The answer is ##"; x
END SELECT
33 INPUT "Would you like to try again (Y/N)"; choice$
SELECT CASE choice$
CASE "y", "Y"
GOTO 2
CASE "n", "N"
SYSTEM
CASE ELSE
GOTO 33
END SELECT
END SUB
--------------------
I want to share choice$ with the main module so I can use it's value to dump the user back to the main interface screen with an IF.... THEN.... statement.
Any ideas?