Because each time I try to assign a word to one it doesn’t work and it results in 1, 2, 3 or 4 because there are 4 variables.
:foodrandom
set /a dish=0
set /a rfood1=4*%random%/32768+1
IF %rfood1%==1 set /a food1=carrots
IF %rfood1%==2 set /a food1=potatoes
IF %rfood1%==3 set /a food1=cabbage
IF %rfood1%==4 set /a food1=corn
set /a rfood2=4*%random%/32768+1
IF %rfood2%==1 set /a food2=hazelnuts
IF %rfood2%==2 set /a food2=acorns
IF %rfood2%==3 set /a food2=apples
IF %rfood2%==4 set /a food2=strawberries
set /a rfood3=4*%random%/32768+1
IF %rfood3%==1 set /a food3=parsley
IF %rfood3%==2 set /a food3=sage
IF %rfood3%==3 set /a food3=rosemary
IF %rfood3%==4 set /a food3=thyme
echo You make a nice meal from a few %rfood1%, some %rfood2% and scent it with some %rfood3%.
echo You win.
ping localhost -n 5 >nul
You need to review the description of
SETcommand.set variable=stringassigns the string to the variable.set /A variable=expressionevaluate the arithmetic expression and assign the numeric result to the variable. In the expression you may use the value of another variable by just using its name.So…
Your command
set /a food1=carrotsmean assign tofood1the same numeric value ofcarrots; if this variable does not exists or contains a non-numeric value, assign a zero. Perhaps the intended result isset food=carrots?Also, note that you are NOT displaying the value of
food1, food2 or food3variables that supposedly contains the strings, you just show the values of therfood...numeric variables…