Click here to Skip to main content
15,881,803 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to calculate in c# the possibility of this game Pin
OriginalGriff22-Aug-20 23:05
mveOriginalGriff22-Aug-20 23:05 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 23:28
Exoskeletor22-Aug-20 23:28 
GeneralRe: How to calculate in c# the possibility of this game Pin
Luc Pattyn23-Aug-20 12:51
sitebuilderLuc Pattyn23-Aug-20 12:51 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor23-Aug-20 13:01
Exoskeletor23-Aug-20 13:01 
GeneralRe: How to calculate in c# the possibility of this game Pin
Luc Pattyn23-Aug-20 13:03
sitebuilderLuc Pattyn23-Aug-20 13:03 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor23-Aug-20 13:06
Exoskeletor23-Aug-20 13:06 
GeneralRe: How to calculate in c# the possibility of this game Pin
trønderen23-Aug-20 13:28
trønderen23-Aug-20 13:28 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor23-Aug-20 13:33
Exoskeletor23-Aug-20 13:33 
that wasnt a hint!!! it appears to be the solution cause now this works

using System.IO;
using System;

class Program
{
    static void Main()
    {
        Console.WriteLine(CalculateProbabilityOfDrawNumbersFromAllNumbers(1,1));
    }
    private static double CalculateProbabilityOfDrawNumbersFromAllNumbers(double drawNumbers, double allNumbers)
        {
            return Factorial(allNumbers) / (Factorial(drawNumbers) * Factorial(allNumbers - drawNumbers)) * (Factorial(80 - allNumbers) / (Factorial(20 - drawNumbers) * Factorial(80 - allNumbers - (20 - drawNumbers)))) / (Factorial(80) / (Factorial(20) * Factorial(80 - 20)));
        }

        private static double Factorial(double x)
        {
            double f = 1;
            while (x > 1)
            {
                f *= x--;
            }
            return f;
        }
}


im not sure why i was getting division by zero error. the int has surpass its largest number and return 0?

i will use this crazy code to display it as a percentage without any unnecessary zeros in the end
Console.WriteLine((CalculateProbabilityOfDrawNumbersFromAllNumbers(12,12) * 100).ToString("F7").TrimEnd(new Char[] { '0' } ).TrimEnd(new Char[] { '.' } )+"%");


modified 23-Aug-20 20:04pm.

GeneralRe: How to calculate in c# the possibility of this game Pin
Luc Pattyn23-Aug-20 15:57
sitebuilderLuc Pattyn23-Aug-20 15:57 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor24-Aug-20 0:35
Exoskeletor24-Aug-20 0:35 
GeneralRe: How to calculate in c# the possibility of this game Pin
Richard MacCutchan24-Aug-20 1:04
mveRichard MacCutchan24-Aug-20 1:04 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor24-Aug-20 1:10
Exoskeletor24-Aug-20 1:10 
GeneralRe: How to calculate in c# the possibility of this game Pin
Eddy Vluggen24-Aug-20 12:52
professionalEddy Vluggen24-Aug-20 12:52 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor24-Aug-20 23:22
Exoskeletor24-Aug-20 23:22 
GeneralRe: How to calculate in c# the possibility of this game Pin
Luc Pattyn24-Aug-20 7:48
sitebuilderLuc Pattyn24-Aug-20 7:48 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor24-Aug-20 23:22
Exoskeletor24-Aug-20 23:22 
GeneralRe: How to calculate in c# the possibility of this game Pin
trønderen26-Aug-20 0:50
trønderen26-Aug-20 0:50 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor23-Aug-20 19:23
Exoskeletor23-Aug-20 19:23 
QuestionHow do I load a block on a form at startup Pin
Brian_TheLion22-Aug-20 18:56
Brian_TheLion22-Aug-20 18:56 
AnswerRe: How do I load a block on a form at startup Pin
BillWoodruff22-Aug-20 19:12
professionalBillWoodruff22-Aug-20 19:12 
AnswerRe: How do I load a block on a form at startup Pin
OriginalGriff22-Aug-20 20:48
mveOriginalGriff22-Aug-20 20:48 
GeneralRe: How do I load a block on a form at startup Pin
Brian_TheLion23-Aug-20 14:33
Brian_TheLion23-Aug-20 14:33 
AnswerRe: How do I load a block on a form at startup Pin
Luc Pattyn23-Aug-20 2:49
sitebuilderLuc Pattyn23-Aug-20 2:49 
AnswerRe: How do I load a block on a form at startup Pin
Gerry Schmitz23-Aug-20 6:48
mveGerry Schmitz23-Aug-20 6:48 
GeneralRe: How do I load a block on a form at startup Pin
Brian_TheLion24-Aug-20 17:03
Brian_TheLion24-Aug-20 17:03 

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.