Open In App

Calculator Program with Batch Scripting in Windows

By using the Batch Scripting of command prompt one could even design a normal basic calculator that takes expressions and returns the result. Type the following script in notepad or any other text editor software:

@echo off
:a
echo ________Calculator________
echo.
set /p expression= Enter expression to calculate:
set /a ans=%expression%
echo.
echo = %ans%
echo
pause
cls
goto a

After writing the above text in a text editor, save the file with the extension “ .bat “. To run the program, simply double-click on the saved file, the program will open and the code will get executed in Command Prompt. It should look something like:

Welcome screen!

Code Explanation and Test Cases:

Program Test Cases:

Calculating Simple Expression

Calculating Complex Expression

Note:-

Article Tags :