In a parenthetical statement, such as a FOR loop or an if statement like this, any variables that are set inside the parentheses, in this case, sum5, will expand to a blank or a previous value if there is one.
if %num2% == 0 (
echo Number not valid, 0 entered
) else (
set /a sum5=%num1% / %num2%
echo %Num1% / %num2% is: %sum5%
)
you have to use delayed expansion. This is because of the way cmd.exe expands the variables at run time.
You have to use this statement (put it at the start just after the @echo off line)
setlocal enabledelayedexpansion
and in the parentheses use exclamation marks (exclamation points if you are American)
like this
num1 and num2 are OK because they were set before the parentheses but sum5 needs delayed expansion.
if %num2% == 0 (
echo Number not valid, 0 entered
) else (
set /a sum5=%num1% / %num2%
echo %Num1% / %num2% is: !sum5!
)
Once you are out of the parentheses you can use % signs again for sum5.
Watch out for spaces in IF comparisons. They can catch you out. This is better
if %num2%==0
This is better still
if "%num2%"=="0"