Click here to Skip to main content
15,613,250 members
Home / Discussions / C#
   

C#

 
AnswerRe: Trying to get my block program working Pin
Gerry Schmitz23-Aug-20 17:18
mveGerry Schmitz23-Aug-20 17:18 
QuestionHow to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 21:43
Exoskeletor22-Aug-20 21:43 
AnswerRe: How to calculate in c# the possibility of this game Pin
OriginalGriff22-Aug-20 21:47
mvaOriginalGriff22-Aug-20 21:47 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 21:51
Exoskeletor22-Aug-20 21:51 
GeneralRe: How to calculate in c# the possibility of this game Pin
OriginalGriff22-Aug-20 22:01
mvaOriginalGriff22-Aug-20 22:01 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 22:04
Exoskeletor22-Aug-20 22:04 
GeneralRe: How to calculate in c# the possibility of this game Pin
OriginalGriff22-Aug-20 22:13
mvaOriginalGriff22-Aug-20 22:13 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 22:31
Exoskeletor22-Aug-20 22:31 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 22:32
Exoskeletor22-Aug-20 22:32 
GeneralRe: How to calculate in c# the possibility of this game Pin
OriginalGriff22-Aug-20 22:33
mvaOriginalGriff22-Aug-20 22:33 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 22:37
Exoskeletor22-Aug-20 22:37 
GeneralRe: How to calculate in c# the possibility of this game Pin
OriginalGriff22-Aug-20 22:43
mvaOriginalGriff22-Aug-20 22:43 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 22:57
Exoskeletor22-Aug-20 22:57 
GeneralRe: How to calculate in c# the possibility of this game Pin
OriginalGriff22-Aug-20 23:05
mvaOriginalGriff22-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 

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.