Help with code for maths script-PLEASE HELP
Posted: 10 Sep 2011 00:17
Hi all,
I need my batch file to receive two numbers from the user, do +, -, *, /, and display the answers.
Then, when the sums are done, it loops to the top. Then if the user types "quit" at any stage of the batch file, it exits.
Here is my current code:
@echo off
:a
@set /p A= Enter first number :
@set /p B= Enter second number :
pause
@set C=%A% + %B% & call :answer
pause
@set C=%A% - %B% & call :answer
pause
@set C=%A% * %B% & call :answer
pause
@set C=%A% / %B% & call :answer
pause
@set C=%A% %% %B% & call :answer
pause
@set abc
if _%abc%==_"quit" goto :quit else goto :a
:answer
@set /A D=%C%
@echo %C%=%D%
:quit
exit
I can get it to do maths, but when I place in the code for the quitting part, it doesn't get past the "Enter first number" and "Enter second number part (it just flashes the black command prompt and exits)
Please help me and feel free to modify my code to give an answer, or else write a completely new script.
Thanks for your effort,
Rileyh
I need my batch file to receive two numbers from the user, do +, -, *, /, and display the answers.
Then, when the sums are done, it loops to the top. Then if the user types "quit" at any stage of the batch file, it exits.
Here is my current code:
@echo off
:a
@set /p A= Enter first number :
@set /p B= Enter second number :
pause
@set C=%A% + %B% & call :answer
pause
@set C=%A% - %B% & call :answer
pause
@set C=%A% * %B% & call :answer
pause
@set C=%A% / %B% & call :answer
pause
@set C=%A% %% %B% & call :answer
pause
@set abc
if _%abc%==_"quit" goto :quit else goto :a
:answer
@set /A D=%C%
@echo %C%=%D%
:quit
exit
I can get it to do maths, but when I place in the code for the quitting part, it doesn't get past the "Enter first number" and "Enter second number part (it just flashes the black command prompt and exits)
Please help me and feel free to modify my code to give an answer, or else write a completely new script.
Thanks for your effort,
Rileyh