Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. //Alice wants to join her school's Probability Student Club. Membership dues are computed via one of two simple probabilistic games.
  2. //The first game: roll a die repeatedly. Stop rolling once you get a five followed by a six.Your number of rolls is the amount you pay, in dollars.
  3. //The second game: same, except that the stopping condition is a five followed by a five.
  4. //Which of the two games should Alice elect to play? Does it even matter? Write a program to simulate the two games and calculate their expected value.
  5. Random rand = new Random();
  6.  
  7. //variables
  8. int previous = -1;
  9. int current;
  10. int counter = 0;
  11. bool condition = false;
  12.  
  13. //five followed by six
  14. while (condition == false)
  15. {
  16. current = rand.Next(1, 7);
  17. counter++;
  18. if (previous == 5 && current == 6) { condition = true; Console.WriteLine("five followed by six cost=" + counter); }
  19. else { previous = current; }
  20. }
  21.  
  22. //resetting variables
  23. previous = 0;
  24. current = 0;
  25. counter = 0;
  26. condition = false;
  27.  
  28. //five followed by five
  29. while (condition == false)
  30. {
  31. current = rand.Next(1, 7);
  32. counter++;
  33. if (previous == 5 && current == 5) { condition = true; Console.WriteLine("five followed by five cost=" + counter); }
  34. else { previous = current; }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement