Welcome to Cancer-Forums.net!   


Useful Links:

American Cancer Society
National Cancer Institute
Cancer Definition

Whats Wrong With My C++ Program?

The latest news from Cancer Trials and Cancer Research around the world.

Whats Wrong With My C++ Program?

Postby zed » Wed Apr 19, 2017 7:22 am

i am a beginner and i am stuck.
my homework is:First your program will input the number of games to simulate.

? Then the program should allow the user to pick a strategy ? 0 means stay with the door choice every

time it runs, and 1 means switch doors every time it runs.

? Then the program prompt the user to pick a door (1-3). The same door will be used for every trial.

? Create a for loop which will run based on the number of games being simulated. The body of the for

loop will contain statements to generate a random number for the door which has the car, an input

which allows the player to choose a door, and a counter to keep track of the number of wins based on

the strategy of staying or switching.

This is what i have(it does not work please help):







using namespace std;

int main()


double win=0;

double mydoor, goatdoor, lastdoor, winning_door;

double strategy, simulated, switch_1;

Posts: 98
Joined: Mon Jun 17, 2013 8:27 pm

Whats Wrong With My C++ Program?

Postby Donato » Wed Apr 19, 2017 7:28 am

I'd like to first say I am really glad you attempted it before posting for help. Most people don't even try.

The most notable problem with your code is that you are using too many loops to perform tasks that can all be done in the single for loop described by your homework.

1.) So to start,

* a.) Get user input : number of trials to execute

* b.) Get user input : Stay @ same door, or choose new each trial.

2.) Second, you should have one for loop, that does the following things inside of it:

* a.) Generate random # for winning door

* b.) Get user input for choice of door, IF user did not select 0 in [#1].

* c.) Increment counter variable if user picks right door

As you can see, it is useful to reformat the word problem into a layout that will effectively outline your goals.

Since you have attempted to do this yourself, I have taken a moment to write a working model for you, which you will need to study and rewrite in your own way. Most teachers check the internet to see if you copy/pasted. So you really MUST learn from this, and rewrite your own code. http://pastebin.com/TVyY9YZW
Posts: 42
Joined: Sat Jan 04, 2014 3:51 pm

Return to Cancer News and Clinical Trials


  • Related topics
    Last post