To create a simple
calculator program that asks the user for two numbers. After the
computer receives two numbers, the program will prompt the user to add,
subtract, multiply or divide the two numbers. the program will display
the answer and prompt the user to repeat the program or quit.
- load your Qbasic program and write the following lines of codes below;
1 CLS
COLOR 7
DIM NUM1 AS SINGLE
DIM NUM2 AS SINGLE
PRINT TAB(30); "A SIMPLE CALCULATOR "
DO WHILE REP$ <> "N"
INPUT "ENTER FIRST NUMBER HERE"; NUM1
INPUT "ENTER OPERATOR HERE"; OPERATOR$
INPUT "ENTER SECOND NUMBER HERE"; NUM2
CALL OPERAN(NUM1, OPERATOR$, NUM2) 'FOR OPERATORS
INPUT "TO QUIT PRESS (N), TO CONTINUE PRESS ENTER"; REP$
REP$ = UCASE$(REP$)
GOTO 1
LOOP
COLOR 4
LOCATE 23: PRINT TAB(30); "@ Jackieriel-Soft 2016, 08114137088 08131327382"
SUB OPERAN (NUM1, OPERATOR$, NUM2)
COLOR 2
PRINT NUM1; OPERATOR$; NUM2; "=";
IF OPERATOR$ = "+" THEN
PRINT NUM1 + NUM2
ELSE IF OPERATOR$ = "-" THEN
PRINT NUM1 - NUM2
ELSE IF OPERATOR$ = "*" THEN
PRINT NUM1 * NUM2
ELSE IF OPERATOR$ = "/" THEN
PRINT NUM1 / NUM2
ELSE
COLOR 4
PRINT " YOU HAVED ENTERED A WRONG OPERATOR SIGN"
BEEP
END IF
END IF
END IF
END IF
CALL FOOTB
END SUB
SUB FOOTB
COLOR 4
LOCATE 23: PRINT TAB(20); "@ JACKIERIEL SOFT 2016, 08114137088, 08131327382"
COLOR 7
END SUB
- After you are done with the code press "F5" to run the program.
If you have any question to ask feel free to contact us.
0 Comments