Wondering if I could get some help...

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
#include<iostream>
#include<cstdlib>

using namespace std;

int main()
{
	int i;
	int numWinsStay =0;
	int numWinsSwitch =0;
	int priceDoor, choiceDoor, switchDoor, revealDoor;
	for(i=0; i<10000;i++)
	{
		priceDoor = rand() %3;

		choiceDoor = rand() % 3;
		revealDoor =0;
		while ((revealDoor == priceDoor) || revealDoor == choiceDoor ))
		{
			switchDoor++;
		}
		switchDoor = 0;

		while (( switchDoor == choiceDoor) || (switchDoor == revealDoor))
		{ 
			switchDoor++;
		}

		if(choiceDoor == priceDoor)
		{
			numWinsStay++;
		}

		else if(switchDoor == priceDoor)
		{
			numWinsSwitch++;
		}
	}

	cout << "If you switch, you will win " << (numWinsSwitch / 100) << "%" << "of the time. " << endl;
		cout << "If you switch, you will win " << (numWinsStay / 100) << "% of the time. " << endl;

		return 0;
}
		


Wondering why this wont build. It is #13 on page 170-172 out of Savitch Problem Solving with C++ Eigth Edition.
"does not build" implies that the compilation fails due to some error. You should tell us the error message.

Note:
Loop on 18-21 does increase switchDoor, but the initial value of switchDoor is unknown and will reset after the loop. More importantly, the body of the loop cannot change the condition of the loop. Either the condition starts false and the loop is skipped, or the condition is true and the loop is infinite.
Feel retarded, forgot a ( on line 18

 
		while ((revealDoor == priceDoor) || revealDoor == choiceDoor ))


But now whenever I run it It opens for a fraction of a second then closes. I added a System("Pause") at the end on line 42, but my Instructor says that if I need a System("pause") then there is something wrong with my code.
For the console closing, see: http://www.cplusplus.com/forum/beginner/1988/
I would ratherno do any of those. My instructor said that his built fine without a system("Pause") or other extramities. So being that his built fine, if can not get mine to build without a extra code such as System("Pause") then I must have a error in my code.
"build" means usually "compiles". There is no console to close.

Running a program is a different matter. If you run in a system that opens a terminal when a program starts and closes it when the program ends, then the terminal indeed closes and disappears in the end. Your teacher apparently does not use such system. You definitely do not want to call external programs, such as 'pause', but you do want the terminal to remain open.
I had gotten it fixed. I had gone to Project > Project Name Properties > Linker > System and set the SubSystem to Console and it now stays open after running. Thanks everyone for the help, you can lock this thread.
Topic archived. No new replies allowed.