Batch File Calculator

Published

Introduction: Batch File Calculator

Hey Guys! marmig0404 here and i just wanted to share my home made simple arithmetic calculator.



Here is the code, just please don't copy and take it as your own. Thank you!



 @echo off
title Calculator
color 0a
echo Welcome to The Basic Arithmetic Calculator
echo Made By Martin Miglio
ping localhost -n 3 >nul

:LOADING
cls
echo Loading.
ping localhost -n 2 >nul
cls
echo Loading..
ping localhost -n 2 >nul
cls
echo Loading...
ping localhost -n 2 >nul
cls
echo Loading....
ping localhost -n 2 >nul
cls
echo Loading.....
ping localhost -n 2 >nul
ping localhost -n 2 >nul
color 0a

:START
cls
echo What Type of Math would you like to do?
echo Add, Subtract, Multiply, or Divide.
set /p math=
IF '%math%' == 'Add' GOTO ADD
IF '%math%' == 'add' GOTO ADD
IF '%math%' == 'Subtract' GOTO SUB
IF '%math%' == 'subtract' GOTO SUB
IF '%math%' == 'Multiply' GOTO MULTIPLY
IF '%math%' == 'multiply' GOTO MULTIPLY
IF '%math%' == 'Divide' GOTO DIVIDE
IF '%math%' == 'divide' GOTO DIVIDE
Exit

:ADD
Cls
GOTO NUMBERSADD
pause
exit

:SUB
Cls
GOTO NUMBERSSUB
pause
exit

:MULTIPLY
Cls
GOTO NUMBERSMULTIPLY
pause
exit

:DIVIDE
Cls
GOTO NUMBERSDIVIDE
pause
exit

:NUMBERSADD
echo What is the First Number you would like to Add?
set /p number1=
cls
echo What is the Second Number you would like to Add?
set /p number2=
cls

GOTO ADD2
exit

:NUMBERSSUB
echo What is the First Number you would like to Subtract?
set /p number1=
cls
echo What is the Second Number you would like to Subtract?
set /p number2=
cls
GOTO SUB2
exit

:NUMBERSMULTIPLY
echo What is the First Number you would like to Multiply?
set /p number1=
cls
echo What is the Second Number you would like to Multiply?
set /p number2=
cls
GOTO MULTIPLY2
exit

:NUMBERSDIVIDE
echo What is the First Number you would like to Divide?
set /p number1=
cls
echo What is the Second Number you would like to Divide?
set /p number2=
cls
GOTO DIVIDE2
exit

:ADD2
Set /A result = %number1% + %number2%
echo The answer is %result%.
Pause
GOTO START
exit

:SUB2
Set /A result = %number1% - %number2%
echo The answer is %result%.
pause
GOTO START
exit

:MULTIPLY2
Set /A result = %number1% * %number2%
echo The answer is %result%.
pause
GOTO START
exit

:DIVIDE2
Set /A result = %number1% / %number2%
echo The answer is %result%.
pause
GOTO START
exit



Thats it!

Share

    Recommendations

    • Clocks Contest

      Clocks Contest
    • Casting Contest

      Casting Contest
    • Woodworking Contest

      Woodworking Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    13 Comments

    Ok, i like the idea, and i have also made a batch calculator of my own. But you see the issue with mine and all of yours. They don't do decimals, message me back if you would like to see my version, or come up with one so that it will do decimals. Thanks.

    here is my batch calculator way better than this hahhahah lol

    Please don't steal it and say it's your's

    ::start copy here

    @echo off

    color 0a

    :: sets

    set num1=

    set num2=

    set sum=

    set div= /

    :home

    title calculator made by andrey.

    cls

    echo welcome to my calculator

    echo.

    echo pick a choice

    echo.

    echo 1 ) plus

    echo 2 ) minus

    echo 3 ) times

    echo 4 ) division

    choice /c 1234 /n

    if %errorlevel% == 1 goto plus

    if %errorlevel% == 2 goto minus

    if %errorlevel% == 3 goto times

    if %errorlevel% == 4 goto div

    :plus

    title plus

    cls

    echo type your numbers

    set /p num1=numbers1:

    set /p num2=numbers2:

    set /a sum=%num1% +%num2%

    echo.

    echo %num1% plus %num2% sum = %sum%

    timeout 1 > null

    echo.

    echo press 1 to go back

    echo press 2 to continue

    choice /c 12 /n

    if %errorlevel% == 1 goto home

    if %errorlevel% == 2 goto plus

    :minus

    title minus

    cls

    echo type your numbers

    set /p num1=numbers1:

    set /p num2=numbers2:

    set /a sum=%num1% -%num2%

    if sum==0 set sum= - 0

    echo.

    echo %num1% minus %num2% sum = %sum%

    timeout 1 > null

    echo.

    echo press 1 to go back

    echo press 2 to continue

    choice /c 12 /n

    if %errorlevel% == 1 goto home

    if %errorlevel% == 2 goto minus

    :times

    title times

    cls

    echo type your numbers

    set /p num1=numbers1:

    set /p num2=numbers2:

    set /a sum=%num1% *%num2%

    if %num1%==0 if %num2%==0 set sum= - 0

    echo.

    echo %num1% times %num2% sum = %sum%

    timeout 1 > null

    echo.

    echo press 1 to go back

    echo press 2 to continue

    choice /c 12 /n

    if %errorlevel% == 1 goto home

    if %errorlevel% == 2 goto times

    :div

    title division

    cls

    echo type your numbers

    set /p num1=numbers1:

    set /p num2=numbers2:

    set /a sum=%num1% / %num2%

    if %num1%==0 %num2%==0 set sum= - 0

    echo.

    echo %num1% divided by %num2% sum = %sum%

    timeout 1 > null

    echo.

    echo press 1 to go back

    echo press 2 to continue

    choice /c 12 /n

    if %errorlevel% == 1 goto home

    if %errorlevel% == 2 goto plus

    user

    lol idk why i share this.

    @echo off

    :again

    color a

    cls

    echo Type an equation.

    set /p x=

    echo %x%

    "%x%"="%x%" goto done

    :done

    color a

    cls

    Set /A result = %x%

    echo %result%

    timeout /t 5

    cls

    color 6

    echo 1:again

    echo 2:exit

    set /p op=

    if %op%== 1 goto again

    if %op%== 2 goto exit

    :exit

    exit

    this is bad because you can use:

    set /p sum=

    set /a ans=%sum%

    so you can use all the functions

    user

    hey just wanted to share my own I am kind of a Newbee In batch programmingan here is a small as I can get the programm :

    @echo off

    mode con: cols=100 lines=20

    Title Basic 2 numbers operations

    :N

    echo *****Basic Calculator By Auto5k*****

    echo choose an operation {1=addition ;2=substraction ;3=multiplication ;4=division}

    echo to exit the program enter {5}

    set /p m=

    if %m%==1 set l=+

    if %m%==2 set l=-

    if %m%==3 set l=*

    if %m%==4 set l=/

    if %m%==5 GOTO E

    GOTO A

    :A

    set /p one=enter your first number

    set /p sec=enter your second number

    set /a rep=%one%%l%%sec%

    echo ****%rep%****

    pause

    GOTO N

    :E

    I made one myself. I like it. just copy and paste it and tell me if you like it or if it sucks.

    --------------------------------------------------------------------------------------------------

    @echo off

    :start

    cls

    echo Welcome to Clown's official calculator Batch file.

    pause

    goto next

    :next

    cls

    echo Type an equation.

    echo Like this: 8 * 8 (replace * with the function you wish to use)

    set /p x=

    echo %x%

    "%x%"="%x%" goto done

    :done

    cls

    Set /A result = %x%

    echo %result%

    pause

    exit

    This one is the most compact version of this calculator I could come up with:

    @echo off

    title calculator

    color 0a

    :1

    cls

    echo.

    echo ===========================

    echo claculator simplified

    echo ===========================

    echo.

    set /p num1= number 1:

    set /p ope= operation:

    set /p num2= number 2:

    if %ope%== + goto add

    if %ope%== - goto sub

    if %ope%== * goto mult

    if %ope%== / goto div

    goto 1

    :add

    cls

    set /a result = %num1% + %num2%

    echo %num1%%ope%%num2% = %result%

    pause

    goto 1

    :sub

    cls

    set /a result = %num1% - %num2%

    echo %num1%%ope%%num2% = %result%

    pause

    goto 1

    :mult

    cls

    set /a result = %num1% * %num2%

    echo %num1%%ope%%num2% = %result%

    pause

    goto 1

    :div

    cls

    set /a result = %num2% / %num2%

    echo %num1%%ope%%num2% = %result%

    pause

    goto 1

    here is a better one with history of calculations;
    @echo off
    title Calculator
    Cls
    color A
    echo.
    echo.
    echo ====================
    echo = Start Calculator =
    echo ====================
    echo.
    echo Press Any Key To Start...
    pause >nul
    echo.
    echo.
    echo ------------------------
    echo Welcome To Calculator!!!
    echo ------------------------
    echo.
    echo _________
    echo Made
    echo By
    echo NinjaXMAt
    echo _________
    echo.
    echo.
    echo.
    echo.
    echo How To Use?
    echo For Calculator Type 1.
    echo Note ** You can only change colour before using calculator!!!
    echo Note ** To Reset, Press r once and hit enter after calculating digits!!!
    echo --Instructions--
    echo Enter Two or More Digits with Special Characters like;
    echo "+" For "Addition"
    echo "-" For "Subtraction"
    echo "*" For "Multiplication"
    echo "/" For "Division"
    echo For Calculator Colour, Type red,green or normal!!!
    :menus
    echo Directory: %CD%
    echo =========
    echo = Menus =
    echo =========
    echo Type;
    echo {1}
    echo {red}
    echo {green}
    echo {normal}
    set /P CMD=Enter Command:
    if "%CMD%" == "red" goto red
    if "%CMD%" == "green" goto green
    if "%CMD%" == "normal" goto normal
    if "%CMD%" == "Red" goto red
    if "%CMD%" == "Green" goto green
    if "%CMD%" == "Normal" goto normal
    if "%CMD%" == "r" goto Reset
    if "%CMD%" == "R" goto Reset
    if "%CMD%" == "%CMD%" goto 1

    %CMD%
    cd C:\
    goto menus

    :red
    color 0c
    goto menus

    :green
    color 0a
    goto menus

    :normal
    color 07
    goto menus

    :1
    echo Input Digit
    set /p Digit=
    set /a ans=%Digit%
    echo Digits Entered="%Digit%">>Log.txt
    echo Ans="%ans%">>Log.txt
    echo.
    echo Ans=%ans%
    set /p reset=
    if "%reset%"=="r" goto Reset
    goto 1
    :Reset
    Cls
    echo Input Digit
    set /p Digit=
    set /a ans=%Digit%
    echo Digits Entered="%Digit%">>Log.txt
    echo Ans="%ans%">>Log.txt
    echo.
    echo Ans=%ans%
    set /p reset=
    if "%reset%"=="r" goto Reset
    goto 1
    1.create a folder
    2. create another folder inside it
    3. create a shortcut of batch file
    4. put it outside of 2nd folder(in first folder)
    5. Launch It

    1 reply

    sorry steps 1-5 are done after pasting code and saving it as batch

    THIS IS A MUCH SIMPLER CALCULATOR

    @echo off
    title Batch Calculator by Thomas.R
    color 0d
    :top
    echo --------------------------------------------------------------
    echo Welcome to Batch Calculator by Thomas.R
    echo --------------------------------------------------------------
    echo.
    set /p sum=
    set /a ans=%sum%
    echo.
    echo = %ans%
    echo --------------------------------------------------------------
    pause
    cls
    echo Previous Answer: %ans%
    goto top
    pause
    exit

    This code is shorter:

    @echo off

    title calculator

    color 0a

    :calculator

    cls

    set /p a=The first number:

    set /p op=Operation:

    set /p b=The second number:

    set /a c=a%op%b

    echo The answer is %c%

    pause>nul

    goto calculator

    Thumb up for the effort, but this solution is terrible, even for a batch.
    Same thing, easier,faster, much less code, and you could calculate whole series of numbers:

    @ECHO OFF
    COLOR a
    TITLE Simple Batch Calculator
    :START
    CLS
    ECHO.
    ECHO. %RESULT%
    ECHO.
    SET/p input="Let's calculate this: "
    SET/a calc=%input%
    SET RESULT=%input%^=%calc%
    GOTO START^=%calc%
    GOTO START

    Before everything you could just create legend about functions...

    lestcalculatethis.png