Monty Hall Game Show Problem

closed account (92yp4iN6)
Hello, so this is one of my first coding challenges and I know it is probably super easy. It is the Monty Hall Problem, but the one difference is that one requirement is to allow the user to select how many doors they want (so it does not have to be three). My code compiles and everything works, the one thing I can not figure out is how to make the switchdoor any door except the firsdoor. I underlined my code where it is located. Thanks!

#include <iostream>
#include <cstdlib>
using namespace std;

int main() {

int doors; //number of doors user enters
int i; //counter
int windoor; //randomly chosen winner door
int firstdoor; //first door chosen
int switchdoor; //switch door chosen
double fcounter = 0; //counter for firstdoor winnings
double scounter = 0; //counter for switchdoor winnings
double fpercent; //percentage of first door winning
double spercent; //percentage of switch door winning

srand(time(0));
cout<<"Enter number of doors: ";
cin>>doors;

for(i=0; i<10000; i++){
windoor = 1 + rand()%(doors);
firstdoor = 1 + rand()%(doors);
switchdoor = 1 + rand()%(doors);

if(firstdoor == windoor){
fcounter++;
}
if(switchdoor == windoor){
scounter++;
}
}
fpercent = (fcounter/100.0);
spercent = (scounter/100.0);
cout<<"Number of winners for first door choice: "<<fcounter<< endl;
cout<<"Number of winners for switch door choice: "<<scounter<< endl;
cout<<"Probability of winning with first door: "<<fpercent<<"%"<<endl;
cout<<"Probability of winning with switch door: "<<spercent<<"%"<<endl;
}
Last edited on
Please use code tags like this:
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
#include <iostream>
#include <cstdlib>
using namespace std;

int main() {

int doors; //number of doors user enters
int i; //counter
int windoor; //randomly chosen winner door
int firstdoor; //first door chosen
int switchdoor; //switch door chosen
double fcounter = 0; //counter for firstdoor winnings
double scounter = 0; //counter for switchdoor winnings
double fpercent; //percentage of first door winning
double spercent; //percentage of switch door winning

srand(time(0));
cout<<"Enter number of doors: ";
cin>>doors;

for(i=0; i<10000; i++){
windoor = 1 + rand()%(doors);
firstdoor = 1 + rand()%(doors);
switchdoor = 1 + rand()%(doors);

if(firstdoor == windoor){
fcounter++;
}
if(switchdoor == windoor){
scounter++;
}
}
fpercent = (fcounter/100.0);
spercent = (scounter/100.0);
cout<<"Number of winners for first door choice: "<<fcounter<< endl;
cout<<"Number of winners for switch door choice: "<<scounter<< endl;
cout<<"Probability of winning with first door: "<<fpercent<<"%"<<endl;
cout<<"Probability of winning with switch door: "<<spercent<<"%"<<endl;
} 


I'm not quite sure I understand what the problem is?
closed account (92yp4iN6)
I will make sure and use code tags in the future. I misinterpreted the directions and found out it is more simple then what I was going for. Thanks for the reply though.
Topic archived. No new replies allowed.