Batch Process Implementation Calculator function code (summary) _dos/bat

Source: Internet
Author: User
Tags arithmetic bitwise clear screen goto numeric value
A small calculator made with bat/batch processing
This is my own bat/batch of small calculator, the following code directly copied into Notepad to save the. bat format can be used.
Support formulas, such as input: 12+12/(7-5), but only integer calculations are supported, decimals are not supported.
The utility is not very big, the technical content is not very high, but the process control is still good. Think logically and abstract thinking is still very strong, also shameless narcissism ~ ~
As follows:
Copy Code code as follows:

@echo off
Cls
:: System Parameter
Set Xpprogname=doscalculator
Set xpprogver=1.0.0.1
Echo.
Title Welcome to use the Taoether compiled small calculator (dcal.bat)%xpprogname%_v%xpprogver%
Color 1f
rem Mode con cols=80 lines=40
Echo welcomes the use of the Taoether-compiled small calculator (dcal.bat)%xpprogname%_v%xpprogver%
if/i {%1}=={} goto Main
if/i "%1" = = "C" goto Main
if/i "%1" = = "H" goto help
if/i "%1" = = "V" goto ver
: Ver
Echo.
REM Important statement:
REM This program is written by Tauyongli, you can spread any, but please do not delete the following information!
REM for commercial use, please contact the author.
Echo Version:
Echo------------------------------
Echo Program:%xpprogname%
Echo Author:taoether
echo Version:%xpprogver%
Echo issuetime:09:01 2009-2-18
Echo updatetime:9:01 2009-6-5
Echo email:taoether@gmail.com
Echo HomePage:www.taoyoyo.net
Echo------------------------------
Echo.
Echo Version Log:
Echo-----------------------------------------
Echo Ver. Date. Log.
Echo-----------------------------------------
echo V1000 20090218 New program issue.
echo V1001 20090605 Add new function:clear.
Echo ...
Echo-----------------------------------------
if/i {%1}=={} goto Main
if/i "%1" = = "H" goto end
if/i "%1" = = "V" goto end
: Help
Echo.
echo Help:
Echo-----------------------------------------
echo This program is a calculator, after entering the calculation expression, returns the result of the calculation.
Echo.
echo dcal [M]
Echo.
echo [M]: Specifies the mode to run
echo = NULL, enter calculation mode
Echo =c, clear screen;
Echo =h, show help;
Echo =v, display version;
Echo.
Echo Description:
Echo.
Echo 1, in calculation mode:
echo directly input the calculation, carriage return returns the calculated result;
Echo Press E, exit the program;
Echo Press H to show help;
Echo Press V, display version;
Echo.
Echo 2, which enables simple computations, supports the following operations in descending order of precedence:
Echo.
Echo ()-Group
echo */%-arithmetic operator
echo +--arithmetic operator
echo ^<^< ^>^>-Logical shift
echo-Bitwise AND
echo ^^-Bitwise "Different"
Echo ^| -Bitwise OR
echo = *=/=%= + = =-Assignment
echo ^&= ^= ^|= ^<^<= ^>^>=-binary operation assignment
echo,-expression separator
Echo.
echo If you use any logic or a fetch-and-take operator, you need to enclose the expression string in quotation marks.
echo any non-numeric string key in the expression as the name of the environment variable, the values of these environment variable names have been converted to numbers before use.
echo If an environment variable name is specified but not defined in the current environment, the value is set to zero.
Echo This allows you to use environment variable values to do calculations without typing those% symbols to get their values.
echo if set/a is executed at the command line outside of the command script, it displays the last value of the expression.
Echo This assigned operator requires an environment variable name to the left of the assigned operator.
Echo has a 0x prefix in addition to hex, octal has 0 prefixes and a numeric value of 10 digits.
Echo therefore, 0x12 is the same as 18 and 022.
Echo Note that the octal formula may be confusing: 08 and 09 are invalid numbers because 8 and 9 are not valid octal digits.
Echo-----------------------------------------
if/i {%1}=={} goto Main
if/i "%1" = = "H" goto end
if/i "%1" = = "V" goto end
: Main
Echo.
Echo enters calculation mode: (Show help: Press H; display version: Press V; Clear screen: press C; exit: Press E)
Echo.
: Calc
set/p input= Please enter an expression:
if/i "%input%" = = "E" goto end
if/i "%input%" = = "H" goto help
if/i "%input%" = = "V" goto Ver
if/i "%input%" = = "C" goto clear
set/a result=%input%
Echo Calculated as:%input%=%result%
Echo.
Goto CALC
: Clear
Cls
if/i {%1}=={} goto Main
if/i "%1" = = "H" goto end
if/i "%1" = = "V" goto end
: End
Echo.
echo Wish you a smooth and happy work!
Echo.

Compact version:
Copy Code code as follows:

@echo off
: Calc
set/p input= Please enter an expression:
set/a result=%input%
Echo Calculated as:%input%=%result%
Goto CALC

A calculator with batch processing, the code is as follows
Copy Code code as follows:

@echo off
: Xixi
set/a A=null
Cls
Set x=
set/p x= expression:
set/a A=%x%>>nul
The echo result is:%a%
Ping-n 5 127.1>nul
Goto Xixi

Like input: 4587*45487+49864-1546545*42431355/54641+15464+554*54545/1213/564354*1234365
You will find that the result is: 208728936
Another example: 12/125+1215+ (13241+12412) *41545
The result is: 1065755100 You can use parentheses, the details can see the detailed use of the set.
Copy the code down and paste it into Notepad, and change the suffix name of Notepad to. BAT Double-click to run directly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.