Click here to Skip to main content
15,891,136 members
Home / Discussions / C#
   

C#

 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
Not Active23-Aug-11 5:39
mentorNot Active23-Aug-11 5:39 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
FunkySteve23-Aug-11 2:47
FunkySteve23-Aug-11 2:47 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
stephen.darling23-Aug-11 3:00
stephen.darling23-Aug-11 3:00 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
KP Lee23-Aug-11 8:43
KP Lee23-Aug-11 8:43 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
riced23-Aug-11 8:56
riced23-Aug-11 8:56 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
KP Lee23-Aug-11 9:56
KP Lee23-Aug-11 9:56 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
riced24-Aug-11 6:56
riced24-Aug-11 6:56 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
KP Lee24-Aug-11 9:58
KP Lee24-Aug-11 9:58 
riced wrote:
Did you read the bit that says generate a four digit number? That won't generate an overflow. Smile | :)

The OP wanted 5 digit numbers.

1. No, I ignored the 5 digit requirement on first reading. My bad.
2. No, I didn't see "generate a four digit number" in the original post and on re-reading still don't see it. Must be written in invisible ink.
3. You are right, no overflow. (Really dumb to use int16 on a 5 digit number because of good chance for overflow.)

I'm going to assume he intended to generate a 5 digit number because he's asking how to modify the last digit. It would be really dumb to ask how to modify the last digit to be divisable by 5 if you start out with 4 digits and want 5. A lot of random number generators produce a number between 0 and 1. You can't get a negative number from that and real numbers have at best 6 digits of accuracy so keeping it down to 5 places makes sense.

If you multiply the real number by 100K it is possible to get a number below 10K.

So, set your int field to 0, while it is 0 set it to the random number times 100K. (Hopefully not an infinite loop Smile | :) ) While it is less than 10K multiply by 5. Then subtract the remainder of 5.
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
riced24-Aug-11 10:21
riced24-Aug-11 10:21 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
Gary Wheeler23-Aug-11 1:13
Gary Wheeler23-Aug-11 1:13 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
Kenneth Kasajian23-Aug-11 3:18
Kenneth Kasajian23-Aug-11 3:18 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
stephen.darling23-Aug-11 3:48
stephen.darling23-Aug-11 3:48 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
Kenneth Kasajian28-Aug-11 11:30
Kenneth Kasajian28-Aug-11 11:30 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
stephen.darling28-Aug-11 11:41
stephen.darling28-Aug-11 11:41 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
Kenneth Kasajian28-Aug-11 18:48
Kenneth Kasajian28-Aug-11 18:48 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
RDSchaefer23-Aug-11 4:11
RDSchaefer23-Aug-11 4:11 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
stephen.darling23-Aug-11 5:34
stephen.darling23-Aug-11 5:34 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
RDSchaefer23-Aug-11 6:07
RDSchaefer23-Aug-11 6:07 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
stephen.darling23-Aug-11 6:52
stephen.darling23-Aug-11 6:52 
SuggestionRe: How do I generate a number divisable by 5, and check it? Pin
Simon Bang Terkildsen22-Aug-11 5:26
Simon Bang Terkildsen22-Aug-11 5:26 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
mooman2723-Aug-11 10:34
mooman2723-Aug-11 10:34 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
riced24-Aug-11 6:58
riced24-Aug-11 6:58 
GeneralMessage Removed PinPopular
22-Aug-11 4:00
David198722-Aug-11 4:00 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
stephen.darling22-Aug-11 23:19
stephen.darling22-Aug-11 23:19 
AnswerRe: How do I generate a number divisable by 5, and check it? Pin
Tom Chantler23-Aug-11 1:15
professionalTom Chantler23-Aug-11 1:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.