Monday, 26 January 2015

Calculator at Command Prompt


Very Interesting..A very simple calculator using Command Prompt BATCH programming.... here is the code below..
========================================================== 
Steps:
1) Open Notepad.
2) paste code and save as 'yourbatchprogramname`.bat
3) open command prompt and goto that directory whre the batch file saved.
4) type `yourbatchprogramname' 3 + 4 <enter>
Exmaple ;
calc 4 + 4 <enter>



=========================================================
Code:

@echo off
IF %2==+ GOTO ADD
IF %2==- GOTO SUB
IF %2==* GOTO MUL
IF %2==/ GOTO DIV
ECHO No Valid Operator Found

:ADD
SET /a VAL=%1 + %3
GOTO DISP

:SUB
SET /a VAL=%1-%3
GOTO DISP

:MUL
SET /a VAL=%1 * %3
GOTO DISP

:DIV
SET /a VAL=%1 / %3
GOTO DISP

:DISP
ECHO %VAL%

No comments:

Post a Comment