I know that there is already an accepted answer but still trying it in one of my own ways. This is an answer using basic Q Basic statements. As told we are going to use locate
command to format the output and align the menu to the center of the screen.
Before starting, you must know that unlike other programming languages, Q Basic has only 25 rows and 80 columns(both numbered from 0).
Syntax for locate command: LOCATE ROW, COLUMN : STATEMENT
This is how you print a string in the middle of the screen: first calculate the length of the string, half of the string must be printed on the right hand side and the rest on the left hand side of the middle column (The middle column is 40). Therefore the column number will be :40 - (length of string / 2). It is not a problem if the column number differs by a number or two.
Type 1:
If you want the menu to be centered and the words to be in the following order(all first letters aligned together)
(A)dd Numbers
(S)ubtract Numbers
(M)ultiply Numbers
(D)ivide Numbers
Here we will calculate the column number using the string (M)ultiply Numbers
or (S)ubtract Numbers
as they have the largest number of characters in them. Therefore the column number is 40 - (18 / 2) = 31.
Then the command using If..Elseif..Else is...
LOCATE 2, 31 : PRINT "(A)dd Numbers"
LOCATE 3, 31 : PRINT "(S)ubtract Numbers"
LOCATE 4, 31 : PRINT "(M)ultiply Numbers"
LOCATE 5, 31 : PRINT "(D)ivide Numbers"
LOCATE 6, 31 : INPUT "ENTER OPTION" ; OPT$
INPUT BLNK 'user must press enter
CLS
'You don't need to worry about whether the string is in upper case or lower
'case as we are going to compare the value only of the string converted
'into upper case using ucase$ function
IF UCASE$(OPT$) = "A" THEN
'The statements required for addition
ELSEIF UCASE$(OPT$) = "S" THEN
'The statements required for subtraction
ELSEIF UCASE$(OPT$) = "M" THEN
'The statements required for multiplication
ELSEIF UCASE$(OPT$) = "D" THEN
'The statements required for division
ELSE PRINT "INVALID OPTION"
END IF
END
The same program using case
LOCATE 2, 31 : PRINT "(A)dd Numbers"
LOCATE 3, 31 : PRINT "(S)ubtract Numbers"
LOCATE 4, 31 : PRINT "(M)ultiply Numbers"
LOCATE 5, 31 : PRINT "(D)ivide Numbers"
LOCATE 6, 31 : INPUT "ENTER OPTION" ; OPT$
INPUT BLNK 'user must press enter
CLS
OP$ = UCASE$(OPT$)
SELECT OP$
CASE "A"
'The statements required for addition
CASE "B"
'The statements required for subtraction
CASE "M"
'The statements required for multiplication
CASE "D"
'The statements required for division
CASE ELSE
PRINT "INVALID OPTION"
END SELECT
END
Type 2:
If you want the menu to be centered for all the options, then like this:-
(A)dd Numbers
(S)ubtract Numbers
(M)ultiply Numbers
(D)ivide Numbers
Then the code is...(but I still prefer the former one to be used, it looks a lot better)
Using If..elseif...end
LOCATE 2, 34 : PRINT "(A)dd Numbers"
LOCATE 3, 31 : PRINT "(S)ubtract Numbers"
LOCATE 4, 31 : PRINT "(M)ultiply Numbers"
LOCATE 5, 32 : PRINT "(D)ivide Numbers"
LOCATE 6, 33 : INPUT "ENTER OPTION"; OPT$
INPUT BLNK 'user must press enter
CLS
IF UCASE$(OPT$) = "A" THEN
'The statements required for addition
ELSEIF UCASE$(OPT$) = "S" THEN
'The statements required for subtraction
ELSEIF UCASE$(OPT$) = "M" THEN
'The statements required for multiplication
ELSEIF UCASE$(OPT$) = "D" THEN
'The statements required for division
ELSE PRINT "INVALID OPTION"
END IF
END
The same program using Case...
LOCATE 2, 34 : PRINT "(A)dd Numbers"
LOCATE 3, 31 : PRINT "(S)ubtract Numbers"
LOCATE 4, 31 : PRINT "(M)ultiply Numbers"
LOCATE 5, 32 : PRINT "(D)ivide Numbers"
LOCATE 6, 33 : INPUT "ENTER OPTION"; OPT$
INPUT BLNK 'user must press enter
CLS
OP$ = UCASE$(OPT$)
SELECT OP$
CASE "A"
'The statements required for addition
CASE "B"
'The statements required for subtraction
CASE "M"
'The statements required for multiplication
CASE "D"
'The statements required for division
CASE ELSE
PRINT "INVALID OPTION"
END SELECT
END
And make sure you fill the places will required statements instead of the ones like ' Statements required for addition.
Hope this helps...