Guest User

Untitled

a guest
Jun 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. bool MontyHall();
  7. int doorEliminator(int x, int y);
  8. void main()
  9. {
  10. srand(time(NULL));
  11. int doorchoice = 0;
  12. int wincounter;
  13. int losscounter;
  14. for(int i=0; i<100; i++) {
  15. cout << "You are a contestant on a game show with a huge grand prize!" << endl;
  16. cout << "I'm your game show host, Monty Hall!" << endl;
  17. cout << "Please pick a door!" << endl;
  18. bool winorlose = MontyHall();
  19. if (winorlose)
  20. cout << "Congratulations! You won $1,000,000!" << endl << endl;
  21. else
  22. cout << "You lost! Better luck next time!" << endl << endl;
  23. }
  24. system("Pause");
  25. }
  26.  
  27. bool MontyHall() {
  28. int winningdoor;
  29. int playerdoor;
  30. int revealedDoor;
  31. int changeDoor;
  32. winningdoor = rand()%3;
  33. playerdoor = rand()%3;
  34. cout << "The winning door is " << winningdoor + 1 << endl;
  35. cout << "You selected door number " << playerdoor + 1 << endl;
  36. changeDoor = rand()%2;
  37. revealedDoor = doorEliminator(winningdoor, playerdoor);
  38. cout << "The revealed door is " << revealedDoor + 1 << endl;
  39. cout << "Would the contestant like to change his answer?" << endl;
  40. if (changeDoor == 0) {
  41. cout << "The player has decided to change his door!" << endl;
  42. playerdoor = 3 - revealedDoor - playerdoor;
  43. cout << "The player's new door is door number " << playerdoor + 1 << endl;
  44. }
  45. else
  46. cout << "The player has decided not to change his door!" << endl;
  47. if (playerdoor = winningdoor)
  48. return true;
  49. else
  50. return false;
  51. }
  52.  
  53. int doorEliminator(int x, int y) {
  54. int revealdoor;
  55. if (x != y) {
  56. revealdoor = 3 - x - y;
  57. }
  58. else
  59. do {
  60. revealdoor = rand()%3;
  61. }
  62. while (revealdoor != x && revealdoor != y);
  63. return revealdoor;
  64. }
Add Comment
Please, Sign In to add comment