I am trying to make a Shutdown dialogue in Batch and I have run into a slight problem. I don't like how Windows 8 asks you for the time in seconds when you would like to remote shutdown your own computer with a timer and I am trying to make a batch file that converts a given number (minutes) into seconds.
I have searched the vast majority of the interwebs and cannot find a way to multiply two whole numbers in a batch file.
Here is what I have so far:
@echo off
echo Enter a number:
set /p %num1%=
echo Enter another:
set /p %num2%=
set /a sum1=%num1%*%num2%
echo The total is %sum1%
pause
Could some kind soul please tell me where I have gone wrong?
Thanks Charlie B
fix to
@echo off
echo Enter a number:
set /p num1=
echo Enter another:
set /p num2=
set /a sum1="num1 * num2"
echo The total is %sum1%
pause
This will do what you want:
@echo off
Echo Time to Shutdown:
set /p "min=Time(Min): "
set /a sec=min*60
shutdown /t %sec%
That doesn't handle invalid input, but for your program that won't be a problem. (If you want it to error handle comment so).
Mona
You don't have to put the "%" in the declaration of your variables
@echo off
echo Enter a number:
set /p num1=
echo Enter another:
set /p num2=
set /a sum1=%num1%*%num2%
echo The total is %sum1%
pause
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With