i am trying to simulate monty hall problem. i didn't realized any problem but i recieve approximately %50 %50 output. i know that there are explanations but i couldnt understand these please help me
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define win 1
#define lose 0
#define yes 1
#define no 0
int main(){
//i assume that prize is behind the first door
srand(time(NULL));
int lose_counter = 0;
int win_counter = 0;
for(int i = 1;i <= 10000;i++){
int game_status;
int chosen_door = rand() % 3 + 1;
int choice;
//first step that i chose a door
if(chosen_door == 1){
game_status = win;
}
else if(chosen_door == 2){
game_status = lose;
}
else if(chosen_door == 3){
game_status = lose;
}
//host says "do you want to change your door"
choice = rand() % 2;
if(choice == yes){
if(chosen_door == 1 ){//this is the case i have chosen
//first door and change it after question
game_status = lose;
}
if(chosen_door == 2 ){
game_status = win;
}
if(chosen_door == 3 ){
game_status = win;
}
}
if(game_status == win){
win_counter++;
}
else if(game_status == lose){
lose_counter++;
}
}
printf("win: %d\nlose: %d\n",win_counter,lose_counter);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire