Калькулятор в командной строке windows


Download Article


Download Article

Making calculations using Windows calculator can get very tedious. Creating your own Command prompt calculator will make your life much easier.

  1. Image titled Make a Command Prompt Calculator Step 1

    1

    Open notepad by going to Start> All Programs> Accessories> Notepad. Vista and 7 users can just type «notepad», without quotes, into the start menu and hit enter

  2. Image titled Make a Command Prompt Calculator Step 2

    2

    Copy the following code:

    • @echo off
    • :start
    • Echo Press 1 for Addition
    • echo Press 2 for Subtraction
    • echo Press 3 for Multiplication
    • echo Press 4 for Division
    • echo Press 5 to Quit
    • set /p type=
    • if %type%==1 goto a
    • if %type%==2 goto b
    • if %type%==3 goto c
    • if %type%==4 goto d
    • if %type%==5 goto e
    • :a
    • echo Addition
    • echo Please choose the 2 numbers you wish to add
    • set /p num1=
    • set /p num2=
    • echo %num1%+%num2%?
    • pause
    • set /a Answer=%num1%+%num2%
    • echo %Answer%
    • pause
    • goto start
    • :b
    • echo Subtraction
    • echo Please choose the 2 numbers you wish to subtract
    • set /p num1=
    • set /p num2=
    • echo %num1%-%num2%?
    • pause
    • set /a Answer=%num1%-%num2%
    • echo %Answer%
    • pause
    • goto start
    • :c
    • echo Multiplication
    • echo Please choose the 2 numbers you wish to multiply
    • set /p num1=
    • set /p num2=
    • echo %num1%*%num2%?
    • pause
    • set /a Answer=%num1%*%num2%
    • echo %Answer%
    • pause
    • goto start
    • :d
    • echo Division
    • echo Please choose the 2 numbers you wish to divide
    • set /p num1=
    • set /p num2=
    • echo %num1%/%num2%?
    • pause
    • set /a Answer=%num1%/%num2%
    • echo %Answer%
    • pause
    • goto start
    • :e
    • echo. Done!

    Advertisement

  3. Image titled Make a Command Prompt Calculator Step 3

    3

    Go to File> Save As

    • Change the «Save as type» box to «All Files»
    • Type «anything.bat» into file name and click «Save»
  4. Image titled Make a Command Prompt Calculator Step 4

    4

    Double click on the file and you will get this window:

  5. Image titled Make a Command Prompt Calculator Step 5

    5

    Follow the simple instructions and your answer will be displayed

  6. Advertisement

Add New Question

  • Question

    Do I save this code on the desktop?

    Community Answer

    You can, yes.

  • Question

    Why are the decimal places not shown for division?

    Community Answer

    The set /a command (used for doing the mathematical operations) cannot display decimal places, so it rounds it down in all cases.

  • Question

    Step 4 is done. What do we have to do in step 5?

    Community Answer

    Try it out!

See more answers

Ask a Question

200 characters left

Include your email address to get a message when this question is answered.

Submit

Advertisement

Thanks for submitting a tip for review!

About This Article

Thanks to all authors for creating a page that has been read 124,062 times.

Is this article up to date?

By using the Batch Scripting of command prompt one could even design a normal basic calculator that takes expressions and returns the result. Type the following script in notepad or any other text editor software:

@echo off
:a
echo ________Calculator________
echo.
set /p expression= Enter expression to calculate:
set /a ans=%expression%
echo.
echo = %ans%
echo
pause
cls
goto a

After writing the above text in a text editor, save the file with the extension “ .bat “. To run the program, simply double-click on the saved file, the program will open and the code will get executed in Command Prompt. It should look something like:

Welcome screen!

Code Explanation and Test Cases:

  • @echo off — signals Command Prompt to not display the commands (code).
  • : a — the signals starting point of a loop.
  • echo — same as print/println/printf/etc. Displays the specified message as output to the screen.
  • echo. — will output a blank line.
  • set — used to set value against a variable.
  • set /p expression — /p signals that this is prompt. “Expression” is just a variable name.
  • set /a ans – /a signal that variable has a numerical value. “ans” is the variable name.
  • %ans% — calls the variable “ans”
  • pause — will pause/ stop the program flow until the user will press a key (any key) and continue the program flow only when the users press a key (any).
  • cls – clears the screen
  • goto a- signals to go to the start point of the loop, effectively looping our calculator program so it can take in and calculate new expression.

Program Test Cases:

  • The program can handle simple expression calculations like:

Calculating Simple Expression

  • And it can also handle complex expressions, such as:

Calculating Complex Expression

Note:-

  • The above program is calculating expressions by utilizing the calculator (that can perform simple arithmetic on 32-bit signed integers) that comes with Command Prompt.
  • Since we are utilizing built-in calculator of Command Prompt, we can only perform following expression: + (addition), – (subtraction), * (multiplication),  / (divide), % (modulo).

Last Updated :
07 Sep, 2020

Like Article

Save Article

create command prompt calculator in windows

Last updated on March 7th, 2023 at 11:03 pm

Creating Own Calculator by using Command Prompt in Windows is such a creative thing. I’ll show you How to make a calculator by using Command Prompt in Windows.

This trick will help you in solving maths problems and complex calculations. Trust me, this is an amazing feeling when you create something useful with your own.

This is an Amazing Command Prompt trick to make a calculator with it. Actually, You need to follow some simple steps to create a Calculator by using Command Prompt.

Actually, You need a piece of code that I’ve provided below. Save the code as a Text file with .bat extension and when you double on this file, This file will open the command prompt window.

Then, you just need to follow the steps to know more about How to Make a Calculator by Using Command Prompt in Windows.


Step 1:  Open Notepad

Make Calculator using Command Prompt in windows

Type in the Windows search bar “Notepad” then you’ll get the Notepad in the list of programs.


Step 2:  Paste Below Code in Notepad

@echo off

 :start

Echo Press 1 for Addition

echo Press 2 for Subtraction

echo Press 3 for Multiplication

echo Press 4 for Division

echo Press 5 to Quit

set /p type=

if %type%==1 goto a

if %type%==2 goto b

if %type%==3 goto c

if %type%==4 goto d

if %type%==5 goto e

 :a

echo Addition

echo Please choose the 2 numbers you wish to add

set /p num1=

set /p num2=

echo %num1%+%num2%?

pause

set /a Answer=%num1%+%num2%

echo %Answer%

pause

goto start

 :b

echo Subtraction

echo Please choose the 2 numbers you wish to subtract

set /p num1=

set /p num2=

echo %num1%-%num2%?

pause

set /a Answer=%num1%-%num2%

echo %Answer%

pause

goto start

 :c

echo Multiplication

echo Please choose the 2 numbers you wish to multiply

set /p num1=

set /p num2=

echo %num1%*%num2%?

pause

set /a Answer=%num1%*%num2%

echo %Answer%

pause

goto start

 :d

echo Division

echo Please choose the 2 numbers you wish to divide

set /p num1=

set /p num2=

echo %num1%/%num2%?

pause

set /a Answer=%num1%/%num2%

echo %Answer%

pause

goto start

 :e

echo. Done!


Copy this CMD Calculator code and paste it in a text file with .bat extension. If you don’t know how to create a new file in windows, let me help you.

  1. Go to Windows Desktop Screen
  2. Right Click >> New
  3. Select the Text File
  4. Paste the code
  5. Give File a name and save as .bat Extension

Step 3:  Save File in Notepad

Make Calculator using Command Prompt in windows

Save Notepad File by clicking on File>>Save As>>Calculator.bat

The .Bat is a File Extension you can’t be changed but you can set any name at the place of Calculator if you want to change the File’s Name.


Step 4: Double Click on the Calculator.bat file and you will get a CMD Window

Make Calculator using Command Prompt in windows

After Creating a File, Double click to open it and file will be open in a Command Window just like the above screenshot.

Then you can select from the numbers to add, subtract, multiply and divide. Enter number and press enter.


Step 5:  Follow Instruction as seen in below Screenshot and your answer will be displayed

Make Calculator using Command Prompt in windows

You have to choose at least two numbers to do the calculations. See in the above screenshot, if you want to add then press 1 and hit enter.

Then, enter two numbers one by one and hit enter. Just like in Screenshot, I am adding 10+10 so firstly I chose 1 for addition.

After that, I entered 10 and hit enter and again 10 and hit enter. That’s how the command prompt calculator roll.

Hello, some time you might face that your windows calculator is not working properly, its unable to open at that time you face a little problem to do any calculation works. But don’t worry, today in this tutorial I will show you another CMD Tricks i.e how to use CMD as a Calculator. Hello This is one of the very simple CMD tricks, just follow these steps and you also able to do calculation with CMD.

Step 1 :- Open wholesale nfl jerseys CMD, wholesale nfl jerseys then cheap jerseys write cheap jerseys China the oz) following wholesale mlb jerseys code.

For addition

Example :

Set /a 324+234

For subtraction

Example :

Set /a 1024-824

For multiplication

Example :

Set /a 234*43

Complex calculation

Set /a (456*(45/5)*6)/6   etc….

Like this you can perform any type of the arithmetic

1

in How-to Guides, Microsoft Windows
Last updated on April 1st, 2022

Generally, for doing any calculation on Windows, we use a calculator or some application, but other than that, we can also use Windows Command Line, i.e., Command Prompt. Calculating arithmetic expressions on the command line is more straightforward and expressive. Because when solving some complex logic, the command line comes in very handy. In this article, we will see how you can calculate using the Windows Command Line, i.e., Windows Command Prompt.

DOS Shell has a built-in mini calculator to perform the simple arithmetic calculation on 32 bit signed integers. The “SET” with /a switch DOS command is used to perform calculations on the command line.

To know more about this command type set /? at the command prompt.

set /a expressionCalculate using dos command line in windows

Here are some expression below

C:\>set /a 3+3 will output 6
C:\>set /a 3*3 will output 9
C:\>set /a  8/4 will output 2
C:\>set /a 2+2 will output 4
C:\>set /a 5*(2/2)+10 will output 15
C:\>set /a (5*2)/2+10 will output 15
C:\>set /a “15>>2” will output 3

It also supports other types of operators. While using a logical or modulus operator, always enclose the expression string in quotes.

The following table lists the operators supported for /a in descending order of precedence.

Operator Operation performed
< > Grouping
* / % + – Arithmetic
<< >> Logical shift
& Bitwise AND
^ Bitwise exclusive OR
| Bitwise OR
= *= /= %= += -= &= ^= |= <<= >>= Assignment
, Expression separator

Note: It overflow values for decimal integer. It eliminates the decimal point value and round of the integer. i.e 9/2 will result in 4 instead of 4.5

  • Камера используется другим приложением что делать windows 10
  • Калькулятор windows 10 скачать без магазина
  • Калькулятор на windows 10 на английском
  • Калькулятор лицензий windows server 2019
  • Камера для распознавания лиц windows hello