using System;
namespace FirstApplication
{
class Program
{
public static void Main()
{
int n = Convert.ToInt32(Console.ReadLine());
int k = Convert.ToInt32(Console.ReadLine());
string category = Console.ReadLine();
double total = 0;
switch (category)
{
case "I":
total = bc(k, 6) * bc(n - k, k - 6) / bc(n, k);
Console.WriteLine("{0:F10}", total);
return;
case "II":
total = bc(k, 4) * bc(n - k, k - 4) / bc(n, k);
Console.WriteLine("{0:F10}", total);
return;
case "III":
total = bc(k, 2) * bc(n - k, k - 2) / bc(n, k);
Console.WriteLine("{0:F10}", total);
return;
}
Console.Read();
}
private static double bc(decimal n, decimal k)
{
if (k == 0 || k == n)
return 1;
return bc(n - 1, k - 1) + bc(n - 1, k);
}
}
}
I have a problem with my code.
The exercise is the following:
You participate at the lottery 6/49 with only one winning variant(simple) and you want to know what odds of winning you have:
-at category I (6 numbers)
-at category II (5 numbers)
-at category III (4 numbers)
Write a console app which gets from input the number of total balls, the number of extracted balls, and the category, then print the odds of winning with a precision of 10 decimals if you play with one simple variant.
For example if I input:
49
6
I
The result is ok, but when I input:
45
15
III
I don’t get any result.
Any suggestions what is wrong with my code?