Problem with Logic

1. ncw
Senior Member
Join Date
Dec 1969
Posts
614

## Problem with Logic

I have a logic problem.<BR><BR>If every multiple of 17, 18, 19, do so and so ...<BR><BR>Eg, <BR>if a &#062; 16 and a &#060; 20 then <BR> ....<BR>end if<BR><BR>if a &#062; 32 and a &#060; 40 then<BR> ...<BR>end if<BR><BR>* the end of the eg.<BR><BR>If I put my code like above, it will be a hardcode type. How my logic should be for this case? Thanks.

2. Senior Member
Join Date
Dec 1969
Posts
96,118

Queston 1: What is true of any multiple of 17 when you divide it by 17?<BR><BR>Question 2: What is true of every number that is *NOT* a multiple of 17 when you divide it by 17?<BR><BR>Questions 3 through 6: Repeat questions 1 and 2 for the number 18 and 19.<BR><BR>Think about this before you look at my answer.<BR><BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
96,118

## No peeking!

Answer to 1 and 2: If you divide a number by 17 and the result is an INTEGER, then the number was a multiple of 17.<BR><BR>So:<BR><BR>&#060;%<BR>If a/17 = a17 OR a/18 = a18 OR a/19 = a19 Then<BR> Response.Write "Number is a multiple of 17, 18, or 19"<BR>Else<BR> Response.Write "Number is NOT a multiple of 17, 18, or 19"<BR>End If<BR>%&#062;<BR><BR>Why does that work? Because the backslash operator in VBScript does an INTEGER ONLY division.<BR><BR>Basically, a17 is the same as writing Int(a/17).<BR><BR>So what we are saying is<BR> If a/17 = Int(a/17) Then ...<BR><BR>In other words, do two steps: <BR> divide a by 17 <BR> check to see if that number is the same as the INT of itself<BR><BR>Example:<BR> 51 / 17 = 3.0<BR> So 51/17 = Int(51/17) <BR> because 3.0 = Int(3.0)<BR>But <BR> 52 / 17 = 3.058...<BR> And Int(3.058) is just 3, so<BR> Int(3.058) &#060;&#062; 3.058<BR><BR>And, once again, writing <BR> 51/7 = 517<BR>is just shorthand for<BR> 51/7 = Int(51/7)<BR><BR>Hokay?<BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
19,082

## RE: No peeking!

can&#039;t you employ &#039;mod&#039; here? <BR><BR>if x mod y = 0 then<BR>&#039; x is a multiple of y<BR>end if

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## Sure...I just figured...

...that maybe understanding <BR> a/17 = Int(a/17) <BR>might be easier.<BR><BR>But sure, you could do<BR> If a MOD 17 = 0 OR a MOD 18 = 0 OR a MOD 19 = 0 Then<BR><BR>[It&#039;s actually a tad faster, since the MOD operator takes the same amount of time as the backslash operator, so you eliminate the other divide.]<BR><BR>Now YOU get to explain what MOD means. &#060;grin/&#062;<BR><BR><BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
19,082

## RE: Sure...I just figured...

&#062; Now YOU get to explain what MOD means. <BR><BR>no problem :<BR><BR>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsoprmod.asp<BR><BR>;-)

7. ncw
Senior Member
Join Date
Dec 1969
Posts
614

## RE: No peeking!

I did thought about it after your questions. Anyway, thanks for your comprehensive answer. Not only you just provide just the answer but prompt me to think about it first. <BR><BR>Atrax, your idea is briliant. I will try it out as well. Thanks guys.

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## Grumble...I should have...

...thought of that. Two points for you.<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•