Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. bool tarkistus (int tot, int draw) {
  7. if ( tot <= 0 or draw <= 0) {
  8. cout << "The number of balls must be a positive number." << endl;
  9. return false;
  10. }
  11. else if ( draw > tot ){
  12. cout << "The maximum number of drawn balls is the total amount of balls." << endl;
  13. return false;
  14. }
  15. else {
  16. return true;
  17. }
  18.  
  19. }
  20.  
  21. int mahdollisuuksia( int n, int p, int np)
  22. {
  23. int m = (n / (np * p));
  24. return m ;
  25.  
  26. }
  27.  
  28. unsigned long int factorial(int n)
  29. {
  30. if(n > 1)
  31. return n * factorial(n - 1);
  32. else
  33. return 1;
  34. }
  35.  
  36.  
  37. int main()
  38. {
  39.  
  40. unsigned long int tot_amount = 0;
  41. cout << "Enter the total number of lottery balls: ";
  42. std::cin >> tot_amount;
  43.  
  44. unsigned long int drawn = 0;
  45. cout << "Enter the number of drawn balls: ";
  46. std::cin >> drawn;
  47.  
  48. if ( tarkistus(tot_amount, drawn) ) {
  49. int n = factorial(tot_amount);
  50. int p = factorial(drawn);
  51. int np = factorial(tot_amount - drawn);
  52. cout << "The probability of guessing all " << drawn << " balls correctly is 1/" << mahdollisuuksia(n, p, np) << endl;
  53. }
  54.  
  55.  
  56.  
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement