Write a qbasic code to create a simple calculator for addition, subtraction,multipication and division operation
Answers
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.
Hope it helps.
Explanation:
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