Click here to Skip to main content
16,006,001 members
Home / Discussions / C#
   

C#

 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
stephen.darling23-Aug-11 5:38
stephen.darling23-Aug-11 5:38 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
Chris Maunder23-Aug-11 6:24
cofounderChris Maunder23-Aug-11 6:24 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
stephen.darling23-Aug-11 6:56
stephen.darling23-Aug-11 6:56 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
Michael A. Cochran23-Aug-11 6:32
Michael A. Cochran23-Aug-11 6:32 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
stephen.darling23-Aug-11 7:00
stephen.darling23-Aug-11 7:00 
GeneralMandatory XKCD reference Pin
jsc4224-Aug-11 1:23
professionaljsc4224-Aug-11 1:23 
AnswerRe: How do I generate a number divisable by 5, and check it? Pin
Vite Falcon23-Aug-11 7:28
Vite Falcon23-Aug-11 7:28 
GeneralRe: How do I generate a number divisable by 5, and check it? Pin
Michael A. Cochran23-Aug-11 9:17
Michael A. Cochran23-Aug-11 9:17 
Why didn't I think of that? Roll eyes | :rolleyes: Too much business programming, I guess. We don't use modulus in business programming much - at least I haven't had the need.

Correct, of course. Much more elegant.

If Stephen is still listening, in C# it becomes;
C#
// To generate as random numbers as possible, this variable must only 
// be initialized once and then reused as much as possible.
Random rand = new Random();

/// <summary>
/// Generates a random number between 0 and 99995 that is always divisible by 5.
/// </summary>
/// <returns>Returns a random integer up to 5 digits long that is evenly divisible by 5.</returns>
private int GetDivBy5()
{
   // Get a random number between 0 and 99999. 
   int divBy5 = rand.Next(0, 99999);
   // Subtract the remainder of (n/5) to make n divisible by 5.
   return divBy5 - (divBy5 % 5);
}

private void button1_Click(object sender, EventArgs e)
{
   this.textBox1.Text = this.GetDivBy5().ToString("00000");

}

GeneralRe: How do I generate a number divisable by 5, and check it? Pin
fuximus23-Aug-11 15:40
fuximus23-Aug-11 15:40 
AnswerRe: How do I generate a number divisable by 5, and check it? Pin
KP Lee23-Aug-11 8:54
KP Lee23-Aug-11 8:54 
AnswerRe: How do I generate a number divisable by 5, and check it? Pin
vaibhav9223-Aug-11 19:34
vaibhav9223-Aug-11 19:34 
AnswerRe: How do I generate a number divisable by 5, and check it? Pin
lukeer23-Aug-11 22:40
lukeer23-Aug-11 22:40 
QuestionC# .net mass emailer Pin
markymark8222-Aug-11 3:38
markymark8222-Aug-11 3:38 
AnswerRe: C# .net mass emailer Pin
jschell22-Aug-11 9:24
jschell22-Aug-11 9:24 
GeneralRe: C# .net mass emailer Pin
markymark8222-Aug-11 22:15
markymark8222-Aug-11 22:15 
GeneralRe: C# .net mass emailer Pin
BobJanova22-Aug-11 23:51
BobJanova22-Aug-11 23:51 
GeneralRe: C# .net mass emailer Pin
markymark8223-Aug-11 0:01
markymark8223-Aug-11 0:01 
GeneralRe: C# .net mass emailer Pin
jschell23-Aug-11 9:31
jschell23-Aug-11 9:31 
QuestionPlease tell me what this silverlight warning message means. Pin
Xarzu21-Aug-11 22:59
Xarzu21-Aug-11 22:59 
AnswerRe: Please tell me what this silverlight warning message means. Pin
Simon Bang Terkildsen21-Aug-11 23:44
Simon Bang Terkildsen21-Aug-11 23:44 
QuestionRun Multiple Forms Pin
share_holder21-Aug-11 22:45
share_holder21-Aug-11 22:45 
AnswerRe: Run Multiple Forms Pin
Wayne Gaylard21-Aug-11 23:00
professionalWayne Gaylard21-Aug-11 23:00 
AnswerRe: Run Multiple Forms [modified] Pin
Shameel21-Aug-11 23:39
professionalShameel21-Aug-11 23:39 
GeneralRe: Run Multiple Forms Pin
BillWoodruff22-Aug-11 3:34
professionalBillWoodruff22-Aug-11 3:34 
GeneralRe: Run Multiple Forms Pin
Luc Pattyn22-Aug-11 3:49
sitebuilderLuc Pattyn22-Aug-11 3:49 

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.