Jump to content

Dos batch help

Go to solution Solved by JFischer00,

PAUSE

Put it at the end.

im trying to make a calculator for my first program, and the cmd opens, then instantly closes.

@echo off
echo /p MATH=equation?
echo /a RESULT=%MATH%
echo %RESULT%

 

SPECS

GPU:Msi r9 270x. PSU:corsair CX600M. CPU AMD-fx 8320. CASE: ultra etorQe mid tower. HDD:1tb barracuda.MOTHERBOARD:ASUS M5A97.

Link to comment
https://linustechtips.com/topic/565588-dos-batch-help/
Share on other sites

Link to post
Share on other sites

dude, it closes at the start, i put a pause, at the start, then i tried the end, and it just closes, as soon as the code runs, it flashes then closes

2 minutes ago, JFischer00 said:

PAUSE

Put it at the end.

 

SPECS

GPU:Msi r9 270x. PSU:corsair CX600M. CPU AMD-fx 8320. CASE: ultra etorQe mid tower. HDD:1tb barracuda.MOTHERBOARD:ASUS M5A97.

Link to comment
https://linustechtips.com/topic/565588-dos-batch-help/#findComment-7432917
Share on other sites

Link to post
Share on other sites

Just now, Gigabiter said:

dude, it closes at the start, i put a pause, at the start, then i tried the end, and it just closes, as soon as the code runs, it flashes then closes

 

@echo off
echo /p MATH=equation?
echo /a RESULT=%MATH%
echo %RESULT%
PAUSE

This code works fine for me.

Link to comment
https://linustechtips.com/topic/565588-dos-batch-help/#findComment-7432931
Share on other sites

Link to post
Share on other sites

You can't just put "10+1" and expect it to understand.

 

@echo off
SET /p num=enter first number?
SET /p num2=enter second number?
echo
echo 1. add
echo 2. subtract
SET /P M=Type 1, 2 then press ENTER:
IF %M%==1 GOTO ADD
IF %M%==2 GOTO SUB

:ADD
SET /A RESULT=%num%+%num2%
GOTO END

:SUB
SET /A RESULT=%num%-%num2%
GOTO END

:END
echo The answer is %RESULT%
Pause

 This should work i cannot test as i am on a chromebook, however i should not that this does not check if the user has put in a number so will likely crash if you put in a letter.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
https://linustechtips.com/topic/565588-dos-batch-help/#findComment-7469804
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×