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

C#

 
AnswerRe: Datagridview to Excel.....using error (again) Pin
SledgeHammer0122-Aug-11 10:38
SledgeHammer0122-Aug-11 10:38 
GeneralRe: Datagridview to Excel.....using error (again) Pin
PDTUM22-Aug-11 16:38
PDTUM22-Aug-11 16:38 
QuestionLevel of privileges Pin
Herboren22-Aug-11 6:36
Herboren22-Aug-11 6:36 
AnswerRe: Level of privileges Pin
Richard Andrew x6422-Aug-11 11:27
professionalRichard Andrew x6422-Aug-11 11:27 
QuestionHow do I generate a number divisable by 5, and check it? PinPopular
stephen.darling22-Aug-11 3:42
stephen.darling22-Aug-11 3:42 
AnswerRe: How do I generate a number divisable by 5, and check it? PinPopular
Luc Pattyn22-Aug-11 3:46
sitebuilderLuc Pattyn22-Aug-11 3:46 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
stephen.darling22-Aug-11 4:01
stephen.darling22-Aug-11 4:01 
AnswerRe: How do I generate a number divisable by 5, and check it? PinPopular
Manfred Rudolf Bihy22-Aug-11 4:47
professionalManfred Rudolf Bihy22-Aug-11 4:47 
What Luc meant was that you should just create a random integer number and the go and multiply it by five. This will always give you a number which is divisible by 5, to state the obvious.

The only thing I would add is if you are given a range in which the numbers should lie you'd need some adjustment.

C#
Random rnd = new Random();

int lowerBound = 2001; // not divisable 5 five
lowerBound = lowerBound + ( 5 - lowerBound % 5 ); // make lowerBound divisable by five

int upperBound = 10023; // not divisable by five
upperBound = upperBound - ( upperBound % 5 ); // make upperBound divisable by five

int range = (upperBound - lowerBound) / 5; // calculate the range of numbers

int number = lowerBound + rnd.Next( range ) * 5; // presto


Cheers!

—MRB

"With sufficient thrust, pigs fly just fine."
Ross Callon, The Twelve Networking Truths, RFC1925

GeneralRe: How do I generate a number divisable by 5, and check it? Pin
GParkings1-Sep-11 7:39
GParkings1-Sep-11 7:39 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
Manfred Rudolf Bihy22-Aug-11 4:52
professionalManfred Rudolf Bihy22-Aug-11 4:52 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
Fabio Franco23-Aug-11 3:04
professionalFabio Franco23-Aug-11 3:04 
AnswerRe: How do I generate a number divisable by 5, and check it? Pin
Luc Pattyn23-Aug-11 3:31
sitebuilderLuc Pattyn23-Aug-11 3:31 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
Fabio Franco23-Aug-11 4:00
professionalFabio Franco23-Aug-11 4:00 
AnswerRe: How do I generate a number divisable by 5, and check it? Pin
riced22-Aug-11 3:54
riced22-Aug-11 3:54 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
stephen.darling22-Aug-11 4:00
stephen.darling22-Aug-11 4:00 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
David198722-Aug-11 4:02
David198722-Aug-11 4:02 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
Luc Pattyn22-Aug-11 4:29
sitebuilderLuc Pattyn22-Aug-11 4:29 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
David198722-Aug-11 5:05
David198722-Aug-11 5:05 
AnswerRe: How do I generate a number divisable by 5, and check it? PinPopular
Luc Pattyn22-Aug-11 5:30
sitebuilderLuc Pattyn22-Aug-11 5:30 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
OriginalGriff22-Aug-11 6:05
mveOriginalGriff22-Aug-11 6:05 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
Luc Pattyn22-Aug-11 13:36
sitebuilderLuc Pattyn22-Aug-11 13:36 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
David198722-Aug-11 6:35
David198722-Aug-11 6:35 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
Luc Pattyn22-Aug-11 13:11
sitebuilderLuc Pattyn22-Aug-11 13:11 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
David198722-Aug-11 20:49
David198722-Aug-11 20:49 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
BobJanova22-Aug-11 23:48
BobJanova22-Aug-11 23:48 

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.