Batch script to simulate a calculator
HEROSKING
-
little boy62 Posted messages 4 Registration date Status Member Last intervention -
little boy62 Posted messages 4 Registration date Status Member Last intervention -
Hello,
Help me, I am a beginner
Explain to me how to create a batch file that simulates the operation of a calculator for integer numbers
1 answer
-
Hello,
Give your code and explain where you are stuck.
-
Hello,
Like this?
@echo off CHCP 65001>nul :START ECHO. SET /P un=Enter first number: SET /P deux=Enter second number: ECHO. CHOICE /C:ASDM /M "Enter the letter of the operation, (A)ddition, (S)ubtraction, (D)ivision, (M)ultiplication:" IF %ERRORLEVEL% EQU 4 GOTO MULTIPLICATION IF %ERRORLEVEL% EQU 3 GOTO DIVISION IF %ERRORLEVEL% EQU 2 GOTO SUBTRACTION IF %ERRORLEVEL% EQU 1 GOTO ADDITION :SUITE CHOICE /C:ON /M "Do you want to perform another operation, (Y)es or (N)o:" IF %ERRORLEVEL% EQU 2 GOTO END IF %ERRORLEVEL% EQU 1 GOTO START :MULTIPLICATION SET /A mult=%un%*%deux% ECHO. ECHO %un% x %deux% = %mult% ECHO. GOTO SUITE :DIVISION IF %deux% EQU 0 ( ECHO Division by zero, please try again! GOTO START ) ELSE ( SET /A div=%un%/%deux% ) ECHO. ECHO %un% / %deux% = %div% ECHO. GOTO SUITE :SUBTRACTION SET /A sub=%un%-%deux% ECHO. ECHO %un% - %deux% = %sub% ECHO. GOTO SUITE :ADDITION SET /A add=%un%+%deux% ECHO. ECHO %un% + %deux% = %add% ECHO. GOTO SUITE :END cls EOF
It seems there was a new fleeting contribution that leads me to a clarification: when you love, you don't count; it's true in this case.
Besides the four basic operations, for which one cannot develop a pure batch calculator, Professor Salmi, who was one of the few batch gurus in the 2000s, proposed several alternatives for more or less sophisticated scientific calculators, but all of them didn't rely on pure batch but on a third-party utility.
See here, tscmd.zip, item 61:
http://ftp.lip6.fr/pub/pc/garbo/pc/link/
-