Help?
Moderator: DosItHelp
-
- Posts: 2
- Joined: 01 May 2012 17:36
Help?
I'm in a bit of a predicament.
I'm trying to get a code that will determine if a random integer is even or odd, and depending on what the answer is perform from two different actions each time the script is referred to.
Here's my code:
set /a compnumber=%random%
set /a modulo = “%compnumber% %% 2?
if %modulo% == 0 (
rem echo EVEN
) else (
rem echo ODD
)
pause
I'm trying to get a code that will determine if a random integer is even or odd, and depending on what the answer is perform from two different actions each time the script is referred to.
Here's my code:
set /a compnumber=%random%
set /a modulo = “%compnumber% %% 2?
if %modulo% == 0 (
rem echo EVEN
) else (
rem echo ODD
)
pause
Re: Help?
dedlygaimer wrote:set /a compnumber=%random%
set /a modulo="%compnumber% %% 2"
if %modulo% == 0 (
rem echo EVEN
) else (
rem echo ODD
)
pause
Re: Help?
Code: Select all
set /a compnumber=%random%
set /a "modulo=compnumber %% 2"
if %modulo% == 0 (
rem echo EVEN
) else (
rem echo ODD
)
pause
Re: Help?
Another method to determine the parity is to make the number and 1 to do a BITAND operation.
Code: Select all
set /a compnumber=%random%
set /a "modulo = compnumber & 1"
if %modulo% == 0 (
rem echo EVEN
) else (
rem echo ODD
)
pause
Re: Help?
Another method:
Code: Select all
@echo off
set num=%1
set num=%num:~-1%
for /f "delims=13579" %%a in ("%num%a") do if "%%a"=="a" (echo odd) else (echo even)
pause
Re: Help?
foxidrive wrote:Squashman wrote:dedlygaimer wrote:Did you even change anything?
I see at least 3 changes to the code.
I see one change. Must be my old eyes.
I also see only one change.
Squashman means to remove the 2 spaces?
set /a modulo_=_"%compnumber% %% 2"
Re: Help?
At least we have more than 2 versions to rely on. But still,
Thank you very much.
Squashman wrote:Removed the spaces.
Added the correct quotes.
Removed the question mark.
Thank you very much.