1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
#include <stdio.h>
#include <cstdlib>
#include <time.h>
#include "after.h"
#include "open.h"
using namespace std;
string s1, s2, s3, s4, s5, str, s1a, s2a, s3a, s4a, s5a, str2;
int reveal_non_chosen_loser(const int & winner);
int decide_non_chosen_loser(const int & winner, const int & chosen);
int higher(const int & a, const int & b);
int lower(const int & a, const int & b);
int wins, times; double percentage_won; char jazz = 'y';
bool first = true;
char x[1000]; char y[1000];
int game()
{
int door = rand() % 3 + 1;
++times;
//printf("Door = %d", door); printf("\n");
int choice;
if (first) { first = false; printf("Hello\nAnd Welcome\n"); }
printf("Please choose a door: 1, 2 or 3.\nIf you choose correctly you will win.\n");
scanf("%d", &choice);
printf("You choose DOOR #%d %s", choice, "\n");
int non_chosen_loser = decide_non_chosen_loser(door, choice);
decide_non_chosen_loser(door, choice);
printf("Lets have a look at whats behind door #%d", non_chosen_loser); printf(" shall we? \n");//, non_chosen_loser);
int sw = rand() % 5; switch(sw){case 1: str = s1; str2 = s1a; break; case 2: str = s2; str2 = s2a; break; case 3: str = s3; str2 = s3a; break; case 4: str = s4; str2 = s4a; break; case 5: str = s5; str2 = s5a; break; default: break; }
char tch [1000];
assign (str, tch);
printf("%s", tch);
printf("\nDo you want to switch to door #%d, or do you feel lucky today? \n", decide_non_chosen_loser(non_chosen_loser, choice));
printf("Y/N\n");
char jas;
scanf("%d", &jas);
if (jas == 'y' || jas == 'Y')
choice = decide_non_chosen_loser(choice, non_chosen_loser);
if (choice == door)
{
++wins;
printf("You win!!!!!!!!!\n");
}
else { printf("!!!!You lose.\n");
int itch = (sw + (rand() % 4) ) % 5 + 1;
switch(itch) { case 1: str = s1; str2 = s1a; break; case 2: str = s2; str2 = s2a; break; case 3: str = s3; str2 = s3a; break; case 4: str = s4; str2 = s4a; break; case 5: str = s5; str2 = s5a; break; default: break; }
assign (str, x); assign (str2, y);
printf("But don't worry you've still won a ");
printf("\n%s%s", x, y );
printf(" ");
printf("\n");
}
return false;
}
int main()
{
open window;
srand(time(NULL));
s1 = "A pile of cow dung. "; s2 = "A goat."; s3 = "A blank sheet of paper. "; s4 = "Absolutely Nothing. "; s5 = "A box. ";
s1a = "Ya know, manure makes excellent fertilizer. \n";
s2a = "They are anything but pickey eaters and can be kept as a pet, if you want. \n";
s3a = "You can write on it, or use it as spare firewood if you need to. \n";
s4a = "Better luck next time. \n";
s5a = "Maybe there's something in it. You never know. \n";
bool again = false;
do
{
game();
printf("Do you want to play again? Y/N ");
printf("\n");
scanf("%c", &jazz);
scanf("%c", &jazz);
scanf("%c", &jazz);
if (jazz == 'Y' || jazz == 'y')
again = true;
else again = false;
}while (again);
percentage_won = (double)wins / (double)times;
printf("wins = %d", wins); printf(" times = %d", times);
printf("\nYou winning percentage = %d", percentage_won);
return 0;
}
int decide_non_chosen_loser(const int & winner, const int & chosen)
{
int loser, temp = rand() % 2;
if (winner != chosen)
loser = (3 - (higher(winner, chosen) + lower(winner, chosen) ) % 3);
else loser = ( ( (winner + temp) % 3) + 1);
return loser;
}
int higher(const int &a, const int & b)
{
if (a > b)
return a;
else return b;
}
int lower(const int & a, const int & b)
{
if (a > b)
return b;
else return a;
}
|