C++ Craps game

I have gotten this far with my program (to make a working craps game with two randomly generated dies), but at the moment I am at a stand still because as soon as you open the program, it closes by itself. To fast for anyone to see what is going on. The program says that there are no errors, but if someone had some advice, I would greatly appreciate it!

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

using namespace std;

int rollDice() {
	return rand() % 6 + 1;
}

int main(){
	srand(static_cast<unsigned int>(time(0))); //seed random number generator
	
	
	cout << "Press enter to roll die 1. " << endl;
	int Die1 = rollDice(); // mandatory function 1
	
	cout << "Press enter to roll die 2. " << endl;
	int Die2 = rollDice();
	
	int sum = Die1 + Die2;

	cout << "You rolled " << Die1 << " + " << Die2 << " = " << sum << endl;

	int determineResults = sum;

	determineResults;
	{	do{
			if (sum == 7 || sum == 11){
				cout << "You won! Pat yourself on the back! " << endl;
				return 0;
			}
			else if (sum == 2 || sum == 3 || sum == 12) {
				cout << "Sorry, you lost. Hey, atleast you didn't bet money on this. " << endl;
				return 1;
			}
			else {
				cout << "You have gained 1 point. Better write that down. " << endl;
				cout << "Try your luck again, buddy! " << endl;
				return 1;
			}
		} while (sum == 7 || sum == 11);
	}
	

	system("pause");
	return 0;
}
cout << "Press enter to roll die 1. " << endl;

This code only prints out you want the user to press enter. There's no implementation to actually wait until the user presses enter.

take a look here:
http://www.cplusplus.com/forum/beginner/1988/

edit: what is the point of lines 25 & 27? and what is the point of the different return statements on lines 31, 35 and 40? It's the presence of these that are making the program complete.
Last edited on
also lines 27, 28, 42 and 43 have no effect

If you really want the user to try again, don't return in line 40, but you'd have to start your loop at line 15
Topic archived. No new replies allowed.