Good To Know:


Oopsie!Either you knew everything or there was a problem in fetching my facts

Posted by : Unknown Saturday, 3 August 2013


A simple Calculator using batch

to create a simple calculator using batch program,copy the below code and paste it into your notepad


@echo off
title simple calculator
color 1f
echo           welcome  :D
:start
echo..........................................
set /p x=Enter calculation :
echo.
set /a result =%x%
echo the result is %result%
echo.
echo..........................................
pause
cls
echo the previous Result is: %result%
goto start


       save it as calculator.bat and the run it.
Explanation:

  • @echo off - to avoid the display of current path
  • title simple calculator - to set the title of the command window (the top part)
  • color 1f - to set the color of the background,text  where 1f is the color code for blue,white (type in "color help" to see the color codes,trust me they are not at all complicated )
  • echo - just to print someting onto the screen
  • :start - indicating the start of a loop
  • set /p x=enter calculation: - to choose a variable x so as to receive an inout from the user and store it.
  • set /a result = %x% -copy the data from the variable x into another variable result and perform the arthamatic calculation.( variable x is represented as %x% it is the notaion used to represent variables in batch )
  • echo result - to display the value in the variable result
  • echo. - to enter a new line
  • pause - to wait untill the user presses another key (see that line waiting at the bottom of the screen saying "press any key..." its a result of this pause command what it does is it simply waits before proceeding to the next line of code )
  • cls - to clear the screen
  • goto start - instruction to go back to the place where :start is and start executing from the next line.

see our batch section for more tutorials

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Translate

Blogger Tips and Tricks

Popular Post

Random post

- Copyright © smartify me -

- Administered by Krishna Chaitanya -
Google+