loading
Hello guys.
When I began learnig batch, one of the first things I did was buid a small calculator, and thoguh it was very simple, it was a greaet start to learning how to utilise variables.

So I decided to make this instructable that will show you how to:
  - Use some basic batch commands
  - how to build a simple caclulator

I've also included a small project of mine, which is currently at v0.8.
I might take it to v1.0, and if I do so i'll update it to this instructable.

NB : The Calculator file at the end of every step is my advanced one

Step 1: Basic Batch

OK, lets start with some commands I'll guarantee you'll use when making a user interactive batch file.
Read this if your new to batch, and even if your not skim it for some usefull things you may not know.

- @echo off
     > Suppresses the console from displaying what commands you type into the batch file and only displays the output data

- Echo [text]
    > Displays the text on the console
____________________________________________________

- Set "var=val"
    > Creates a variable named "var" with the value of "val"

- Set /p "var=Prompt"
    > Prompts the user with "Prompt" and what ever they input becomes te value of "var"

- Set /a "var=Equation"
    > Solves "Equation" as a maths equation and sets the value to "var"

- %var%
    > Refers to the variable amed "var"

- %var:~[Refer to values within "var"]%
    > To learn how to use the above type "set /?" in cmd.
____________________________________________________

- if "%var%" equ "val" [command]
    > Executes [command] if %var%=val (if /? for more info)
- :tag
    > Creates a tag called "tag" which can be later referenced
- goto tag
    > Goes to the tag labelled "tag"
____________________________________________________

- Color [hex][hex]
    > Sets teh current console colour to the two hexadecimal numbers (color /? for more info)

- Rem
    > A line starting with Rem will be completly ignored. It's used to organsise the file or help someone else understand it.

- Title Program Name
    > Sets the console's title to "Program Name"

- Pause
    > Displays "Press any key to continue . . ." and continues upon user input

- Exit
    > Immeadiately exits the batch file

And thats your crash course to batch!

Of coourse, type help to learn more. Lastly this is nothing compared to some of the operatable programs built in to windows. And nothing when compared to building you own operable programs!

But this is just your first little step...

Step 2: Your Calculator!

Ok, heres the step to build your calculator. I'm not going to explain it, so when you realises how it works (from the last step) you'll be extra proud of yourself, and you'll have a better understanding (Cuz you actually thought about it!).

Firstly open notepad.

In notepad type the code:

@echo off
Title My Calculator!
color 0a

:loop
set /p "input=Calculate: "
set /a answer=%input%
Echo =%answer%
Echo.
Echo.
goto loop

Rem This Line is a remark and will be ignored. So will the below line. Its just good practice to End all Batch Files like this
Exit /b 0


And thats it
NB: Echo. Leaves a blank line

Then Ctrl+S to save and save as "Calculator.bat" with the option "allfiles" selected (note ".txt - Text Document") Some versions of Windows will not except the latter.

Finally find and run it and have FUN!!! Modify it to make it Mind blowing!

Step 3: Try My Calculator

Here's my calculator, in Version 0.8:

If I do update it I'll put ip up here again.
If you want me to make more steps (or a new instructable) Explaining how to build one like mine, Comment.

Note, when using it type "?" so you know how to use it.

Don't dedicate your life to finding cases where it breaks. Dedicate your life to:

              conveying potential aspects of belief or opinon which may or may not have didactic influence over others who amy ever wish to accept so of the great potential and power of a simple automated series of tasks which take user input and resolves it to the humans standard of maths, with the awkward fact that the functions require the operator to be placed in fromt of the operand???

I'll go neck my self about. . . . . . . . . . . . Pause . . . . . . . . . . . . . Now!
<p>Hi Monacraft,</p><p>I made a simple calculator that cannot calculate exponents, etc.</p><p>Can you put all the commands together so that I would have an advanced calculator? So that I would be able to calculate exponents, Stuff like 3^4= ... and and so on...</p><p>I am not that good in batch scripting and I don't know how to add those stuff :(</p><p>Here is my code:</p><p>@echo off</p><p>:start</p><p>set /p MATH=Equation?</p><p>set /a RESULT=%MATH%</p><p>echo %RESULT%</p><p>pause</p><p>cls</p><p>goto start</p>
<p>Hi Monacraft,</p><p>I made a simple calculator that cannot calculate exponents, etc.</p><p>Can you put all the commands together so that I would have an advanced calculator? So that I would be able to calculate exponents, Stuff like 3^4= ... and and so on...</p><p>I am not that good in batch scripting and I don't know how to add those stuff :(</p><p>Here is my code: </p><p>@echo off</p><p>:start</p><p>set /p MATH=Equation?</p><p>set /a RESULT=%MATH%</p><p>echo %RESULT%</p><p>pause</p><p>cls</p><p>goto start</p>
<p>Is there a code I can use to get powers. I am trying to find one for my <a href="https://www.instructables.com/id/Batch-Calculator-3/" rel="nofollow">calculator</a>.</p>
<p>Hello Governor, </p><p>Exponents aren't too hard in batch, all they require is a simple for-loop. Here is a sample code which returns x^a or in this case 2^4=16.</p><p>================================</p><p>set /a x=2</p><p>set /a a=4</p><p>for /l %%a in (2, 1, %a%) do (</p><p>set /a x*=%x%</p><p>)</p><p>Echo %x%</p><p>pause</p><p>================================</p><p>If you run that, it should print out 16. Hopefully that shouldn't be too hard to incorporate into your program. Sorry for taking so long to respond to your question (I've been having internet problems :/ ). If you have anyother questions, comment or email me and I should reply in about a week :D.</p>

About This Instructable

2,766views

9favorites

License:

Bio: Done Batch Scripting and Automating of tasks for quite a while. Similarly practiced HTML and CSS for web design as well as basic VBscript for ... More »
More by Monacraft:What Every Chrome Browser Needs Old School Batch Trolls Build a Batch Calculator + Advanced Calculator v0.8 
Add instructable to: