Batch File Calculator

24,742

6

17

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

    • 1 Hour Challenge

      1 Hour Challenge
    • Sensors Contest

      Sensors Contest
    • Classroom Science Contest

      Classroom Science Contest

    17 Discussions

    0
    None
    AaronYT999

    5 months ago

    i made very few changes and i made it more annoying with the load... here you have
    @echo off
    title The CMD Calculator
    color 0a
    echo.
    echo.
    echo Welcome to The CMD Calculator!
    echo Made By Martin Migilio, changes by AaronYT.
    ping localhost -n 3 >nul
    cls
    echo.
    echo Welcome to The CMD Calculator!
    echo Made By AaronYT.
    ping localhost -n 2 >nul
    cls
    echo Welcome to The CMD Calculator!
    echo Made By Martin Migilio, changes by AaronYT.
    ping localhost -n 2 >nul
    cls
    echo Made By Martin Migilio, changes by AaronYT.
    ping localhost -n 2 >nul
    cls
    echo.
    ping localhost -n 2 >nul
    cls
    echo.
    ping localhost -n 2 >nul
    cls
    :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
    cls
    :START
    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
    echo Calculating...
    ping localhost -n 5 >nul
    cls
    Set /A result = %number1% + %number2%
    echo The answer is %result%.
    Pause
    echo loading...
    ping localhost -n 10 >nul
    cls
    GOTO START
    exit
    :SUB2
    echo Calculating...
    ping localhost -n 5 >nul
    cls
    Set /A result = %number1% - %number2%
    echo The answer is %result%.
    pause
    echo loading...
    ping localhost -n 10 >nul
    cls
    GOTO START
    exit
    :MULTIPLY2
    echo Calculating...
    ping localhost -n 5 >nul
    cls
    Set /A result = %number1% * %number2%
    echo The answer is %result%.
    pause
    echo loading...
    ping localhost -n 10 >nul
    cls
    GOTO START
    exit
    :DIVIDE2
    echo Calculating...
    ping localhost -n 5 >nul
    cls
    Set /A result = %number1% / %number2%
    echo The answer is %result%.
    pause
    echo loading...
    ping localhost -n 10 >nul
    cls
    GOTO START
    exit

    1 reply
    0
    None
    NathanDCodeGeekAaronYT999

    Reply 6 days ago

    why would you make a loading screen to wait for nothing? you can remove that whole part and replace it with
    title Made by: {...} Changes made by: {...}
    if you want to creddit yourself or other people.

    Just wanted to say:
    Making an "if" for all actions is not verry efficient i did it in a shorter way with just doing this. Don't copy as your own please.

    Echo off
    Title Nathans OG Calculator
    color F0
    cls
    Goto Start

    :Start
    cls
    set /p Numberone=Number one:
    Set /p Action=Action:
    Set /P Numbertwo= Number two:
    Set /A Outcome=%Numberone% %Action% %Numbertwo%
    echo %outcome%
    Set /p ResetYN=Do you want to calculate something else? (Y/N)
    If "%ResetYN%"=="Y" (
    Goto Start
    ) Else (
    Goto End
    )
    :End
    Cls
    Exit

    this way you also don't have to type out your action like ADD or MULTIPLY, you can just use /*-+. i am working on adding root and squared later. allthoug it is shorter this can't calculate things like 1 + 1 +3 because it can only calculate with two nubers. have seen two other answers to that problem already below this.

    0
    None
    Csongor

    6 weeks ago

    @echo off
    :doMath
    set /p math="Question: "
    set /a answer=%math%
    echo Your answer is: %answer%
    PAUSE
    GOTO doMath


    Just a bit shorter

    0
    None
    AJWSayden

    1 year ago

    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.

    0
    None
    AndeyV

    1 year ago

    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

    0
    None
    SutN

    2 years ago

    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

    0
    None
    ICTrix

    2 years ago

    this is bad because you can use:

    set /p sum=

    set /a ans=%sum%

    so you can use all the functions

    0
    None
    gv11

    2 years ago

    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

    0
    None
    SebastianP85

    3 years ago

    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

    0
    None
    Lenny God

    3 years ago

    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

    0
    None
    ShoshO1

    3 years ago on Introduction

    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
    0
    None
    GamingD

    4 years ago on Introduction

    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

    0
    None
    xZero707

    4 years ago on Introduction

    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