I am making a simple calculator in QBasic, for that want to implement a Menu, the practice which I followed was:
PRINT "Select an Option"
PRINT "1. Addition"
PRINT "2. Subtraction"
PRINT "3. Multiplycation"
PRINT "4. Division"
PRINT "Option No.: "
INPUT opt
CLS
SELECT CASE opt
CASE 1
PRINT "You have selected Addition"
PRINT "Enter a no.:"
INPUT n1
PRINT "Enter second no.:"
INPUT n2
PRINT "The Sum is "; n1 + n2
CASE 2
PRINT "You have selected Subtraction"
PRINT "Enter a no.:"
INPUT n1
PRINT "Enter second no.:"
INPUT n2
PRINT "Difference between "; n1; " and "; n2; " is "; n1 - n2
CASE 3
PRINT "You have selected Multiplycation"
PRINT "Enter a no."
INPUT n1
PRINT "Enter second no.:"
INPUT n2
PRINT "Product is "; n1 * n2
CASE 4
PRINT "You have Selected Division"
PRINT "Enter a no.:"
INPUT n1
PRINT "Enter second no.:"
INPUT n2
PRINT "The Quotient is "; n1 / n2; " and the remainder is "; n1 MOD n2
CASE ELSE
PRINT "Invalid Option Number"
END SELECT
But this time I want a more sophisticated one, like:
(A)dd Numbers
(S)ubtract Numbers
(M)ultiply Numbers
(D)ivide Numbers
This all in a Box that is centered on the Screen. I am using LOCATE
, but I am not getting the results I want, and yes I am trying this without Graphics.
I'm also using INKEY$
to get the key entered by user. I tried INPUT
but it echoed the character typed by user.
EDIT: @user2864740, it means that I was not able to get the perfect coordinates.
Here is something for you. It is fairly basic (no pun intended), but it is worth looking at. I will say it is untested, so it may not work as intended. It should give you an idea on how to do things.
Also, be careful when using
INKEY$
. Press an arrow key for example. An arrow key is an example of an extended key, and there are others too. This is why the loop is designed the way it is.LEN(INKEY$) > 1
when an extended key is pressed, unlike a letter or a number whereLEN(INKEY$) = 1
.If you need reference material, the wiki at http://www.qb64.net/wiki/ should still be reliable. There is a link to an index on that page, or you can use the search box in the navigation area on the left to find what you need.