Skip to content

Instantly share code, notes, and snippets.

@Richienb
Created September 9, 2018 04:16
Show Gist options
  • Save Richienb/7b2189ff0fb9e85c06cc62a8979648da to your computer and use it in GitHub Desktop.
Save Richienb/7b2189ff0fb9e85c06cc62a8979648da to your computer and use it in GitHub Desktop.
A simple, easy calculator in bash
@echo off
title Richie's Calculator
:main
cls
echo Welcome %USERNAME% to
echo Richie's Calculator 2.0
echo -------------------------
echo Your previous Calulated number was %sum%
echo -------------------------
echo Enter the the corresponding letter for the calculation you want to do
echo.
echo a)Addition
echo b)Subtraction
echo c)Divison
echo d)Multipication
echo e)Square, Cube or any power
echo -------------------------
set /p do=letter:
if %do%== a goto add
if %do%== A goto add
if %do%== b goto sub
if %do%== B goto sub
if %do%== c goto div
if %do%== C goto div
if %do%== d goto mul
if %do%== D goto mul
if %do%== e goto power1
if %do%== E goto power1
echo Invalid value = %do%
echo.
pause
cls
goto main
:add
echo -------------------------
echo Addition
echo.
set /p no1="1st Number:"
echo +
set /p no2="2nd Number:"
set /a sum=no1+no2
echo -------------------------
echo %sum%
echo.
pause
cls
goto main
:sub
echo -------------------------
echo Subtraction
echo.
set /p no1="1st Number:"
echo -
set /p no2="2nd Number:"
set /a sum=no1-no2
echo -------------------------
echo %sum%
echo.
pause
cls
goto main
:div
echo -------------------------
echo Division
echo.
set /p no1="1st Number:"
echo /
set /p no2="2nd Number:"
set /a sum=no1/no2
echo -------------------------
echo %sum%
echo.
pause
cls
goto main
:mul
echo -------------------------
echo Multiplication
echo.
set /p no1="1st Number:"
echo *
set /p no2="2nd Number:"
set /a sum=no1*no2
echo -------------------------
echo %sum%
echo.
pause
cls
goto main
:power1
echo -------------------------
echo Square, Cube or any power
echo.
echo Select the number
set /p num=
echo Select the power
set /p pow=
set /a pow=%pow%+1
set ans=%num%
:power2
set /a pow=%pow%-1
if %pow% LSS 1 goto next
set /a ans=%ans%*%num%
goto power2
:next
echo Your answer is %ans%
echo.
echo Type 'M' to go back to the starting screen
::To open Prof.Pickle's instrutable's profile type 'I'.
set /p open=
if %open%== I start http://www.instructables.com/member/Prof.+Pickle/
if %open%== i start http://www.instructables.com/member/Prof.+Pickle/
if %open%== m goto main
if %open%== M goto main
goto main
@echo off
title Richie's Calculator
:main
cls
echo %USERNAME%, welcome to ROS Calculator 3.0
echo -------------------------
echo The answer to your previous calculation is %sum%
echo -------------------------
echo Enter the corresponding letter for the operator you wish to use
echo.
echo (A)ddition
echo (S)ubtraction
echo (D)ivison
echo (M)ultipication
echo (P)ower
echo -------------------------
set /p do="Chosen operator: "
if %do%== A goto add
if %do%== a goto add
if %do%== S goto sub
if %do%== s goto sub
if %do%== D goto div
if %do%== d goto div
if %do%== M goto mul
if %do%== m goto mul
if %do%== P goto power1
if %do%== p goto power1
echo Your choice (%do%) is invalid.
echo Press any key to try again...
pause>nul
goto main
:add
echo -------------------------
echo You have chosen addition
call getnums
set /a sum=no1+no2
goto afterit
:sub
echo -------------------------
echo You have chosen subtraction
call getnums
set /a sum=no1-no2
goto afterit
:div
echo -------------------------
echo You have chosen division
call getnums
set /a sum=no1+no2
goto afterit
:mul
echo -------------------------
echo You have chosen multiplication
call getnums
set /a sum=no1+no2
goto afterit
:power1
echo -------------------------
echo You have chosen power
echo.
set /p num="Number: "
set /p pow="Power: "
set /a pow=%pow%+1
set ans=%num%
:power2
set /a pow=%pow%-1
if %pow% LSS 1 goto next
set /a ans=%ans%*%num%
goto power2
:next
set /a sum=%ans%
goto afterit
:getnums
echo.
set /p no1="The 1st number: "
set /p no2="The 2nd number: "
:afterit
echo -------------------------
echo You answer is %sum%
echo.
echo Press any key to go back...
pause>nul
goto main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment