Simple calculator by batch console

4

In class we are doing an exercise of making a calculator in batch . I wanted to make my own and simple, instead of taking one out there. In theory it should work, but the only thing it does when I enter the data is put:

  

"echo is disabled"

This is my code:

@echo off
title Calculadora
echo "Calcualdora"
set/p numero1 = 
set/p operacion= 
set/p numero2 = 
If %operacion%=='+' set/a resultado=%numero1% + %numero2%
If %operacion%=='-' set/a resultado=%numero1% - %numero2%
If %operacion%=='*' set/a resultado=%numero1% * %numero2%
If %operacion%=='/' set/a resultado=%numero1% / %numero2%
echo %resultado%
echo.
pause
exit
    
asked by Alumno 11.11.2016 в 10:22
source

4 answers

2

You have some faults. Use this code:

@echo off
title Calculadora
echo "Calculadora"
set resultado= 0
set/p numero1= Introduce el primer numero: 
set/p operacion= Introduce la operacion: 
set/p numero2= Introduce el segundo numero: 
if %operacion%==+ set/a resultado=%numero1% + %numero2%
if %operacion%==- set/a resultado=%numero1% - %numero2%
if %operacion%==* set/a resultado=%numero1% * %numero2%
if %operacion%==/ set/a resultado=%numero1% / %numero2%
echo Resultado %numero1% %operacion% %numero2% = %resultado% 
echo.
pause
    
answered by 11.11.2016 / 11:00
source
0

It is in the%% share% That does not make an impression of echo %resultado% , if you remove "echo" from that part, it will not show you that message anymore.

    
answered by 11.11.2016 в 10:49
0

I know it's been a while now ... But I still want to contribute to the answer:

CHANGES

By doing this we simplify the previous codes, so that we can calculate operations with only 2 operands, or, to do combined operations

PD : This code has the boxes to make it more aesthetic, to put it one way ..

  

HERE IS MY CODE:

@echo off
title CALC
color 70
mode con cols=50
mode con lines=15
:inicio
echo  ------------------------------------------------
echo         Welcome to Calculator      
echo  ------------------------------------------------
echo  Escriba la operacion..
set /p sum= 
set /a ans=%sum%
echo.
echo  = %ans%
echo  ------------------------------------------------
ECHO Presione ANY KEY para reiniciar..
pause >nul
cls
goto inicio
    
answered by 28.01.2018 в 00:27
-1

You must initialize the variables numero1 and numero2 , for example:

set num1=0
set num2=0
    
answered by 11.11.2016 в 10:25