|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Code:
if intNumber Mod 2 = 0 then intnumber = intNumber - 1 End if
__________________
Fisherman "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein |
|
#2
|
|||
|
|||
|
I am learning Visual basic 6.0 on my own. I need to know how to write a function that returns the highest odd integer that is not greater than the parameter. How do I write code that determines odd from even numbers?
|
|
#3
|
|||
|
|||
|
Code:
If number mod 2 = 0 then 'even Else 'odd End If |
|
#4
|
|||
|
|||
|
I am trying to write a function that if I typed in 17 I would get 17 and if i typed in 12 i would get eleven. i am very confused. help!!!
|
|
#5
|
|||
|
|||
|
How did Fisherman's post get to the top of the list, I wonder? It is the answer you need
![]() |
|
#6
|
||||
|
||||
|
very strange, Doug... I can't explain that one
The board just likes me I guess! |
|
#7
|
|||
|
|||
|
Quote:
With all the help you give here, you deserve the top of the list! I think there was a timestamp hiccup with the server.
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
|
#8
|
|||
|
|||
|
if it's a function you need, then
Private Function OddOrEven(temp as Integer) as Integer if temp mod 2 = 1 then 'temp is odd, so the function returns the same number OddOrEven = temp else 'temp is even, so the function returns one less OddOrEven = temp - 1 end if end function |
|
#9
|
||||
|
||||
|
Good point, if you have to do it over and over - make it a function! I would recommend making the return value a boolean though
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Recognizing odd or even integers |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|