Solved Hello to all can you help with this cmd

October 2, 2013 at 10:11:20
Specs: Windows 7
iwhen i run this, and enter an operand it says missing operand

@ echo off

echo TITLE (Leonine) Calculator!
Color 70
: top
echo .....
echo - Welcome to (Leonine) calculator!
echo -----
echo ENTER YOUR OPERAND
echo .
Set /p sum=
Set /a ans=%sum%
echo .
echo =%ans%
echo -----
Pause
CLS
echo Previous Answer: % Ans %
goto TOP
PAUSE
EXIT


See More: Hello to all can you help with this cmd

Report •

#1
October 2, 2013 at 18:16:58
✔ Best Answer
Initially, it looks like you're entering a null-RETURN (ENTER), so obv. there will be no available operand.
Then, well, there's lots of small mistakes, and some not-so-small. Small catagory: I would recommend "setlocal", so your var values don't get confused with global var values.I always recommend neutralizing a variable before SET /P. ECHO . just echoes a dot (maybe your intent?), ECHO. echos a null line-feed. And when you tried to echo ANS, you can't put spaces like you did: ECHO PREVIOUS % ANS %.
Your concept is excellent. I did change the name of var. ANS to X, so the user can apply the math to the current "subtotal" by invoking x in the string, like this, f/e: x+22. This will add 22 to to the current running total. X is just an example. You could still use ANS, but that's 3 letters to type instead of one. Here's my version of your calculator with the aforementioned issues addressed somewhat:
:: recommending "setlocal"
@ echo off & setlocal

echo TITLE (Leonine) Calculator!
Color 70
:top
echo .....
echo - Welcome to (Leonine) calculator!
echo -----
echo ENTER YOUR OPERAND
echo.
::always clear a var. before SET /P else it retains its previous value on a null-ENTER
set sum=
Set /p sum=
:: this next enables a graceful "prog.term" exit when user enters a null
:: it might also be an exit-routine with a query like "done?" etc.
if not defined sum goto :xit
Set /a x=%sum%
echo.
echo =%x%
echo -----
Pause
CLS
echo Previous Answer accessible as X: %x%
goto TOP
:xit
echo bye
:: it's always polite to restore the color to default
color
::====== end script
ps: you ARE aware that batch only does integer math. Division results will be truncated to integers.

message edited by nbrane


Report •

#2
October 3, 2013 at 01:01:19
thanks a lot! : )

Report •
Related Solutions


Ask Question