Trying to add the three constants

So the assignment requires us to make a game of Craps and also put three constants in the program. The game works I'm just trying to figure out how I would get a constant into the code. I have set three constants. SnakeEyes = 2, Boxcars = 12, and BigRed =7. Should I be going at this another way?

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  #include <iostream>
#include <ctime>
#include <time.h>
#include <cstdlib>

using namespace std;

int main()
{
	int die1; //The first die.
	int die2; //The second die.
	int rollingDice; //When the player throws dice
	int rollingDice2 = 0; //When the player throws the dice if the first throw didn't give a winning or losing outcome.
	const int SnakeEyes = 2; //If the player throws two ones.
	const int BoxCars = 12; //If the player throws two sixes.
	const int BigRed = 7; //If the player throws a three and four

	srand(22);

	die1 = rand() % 6 + 1; //Simulates a six sided die
	die2 = rand() % 6 + 1;
	rollingDice = die1 + die2; //Adds the dice together.



	cout << "Player rolled: " << die1 << " + " << die2 << " = " << rollingDice << endl << endl; //Shows what the player rolled on first try.

	if (rollingDice == 7 || rollingDice == 11) //Player wins if they get a 7 or 11.
        {
            cout << "You won!" << endl;
            cin.get();
            return 0;
        }

	if (rollingDice == 2 || rollingDice == 3 || rollingDice == 12) //Player loses if they get a 2, 3, or 12 on first try.
        {
            cout << "Craps! You lost!" << endl;
            cin.get();
            return 0;
        }


	else
        {
            cout << "The Point is " << rollingDice << endl << endl; //If the player rolled a 4, 5, 6, 8, 9, or 10 on first try the game continues.
        }

        if (rollingDice == BoxCars)
    {
        cout << "Boxcars!" << endl;
    }

	while (rollingDice2 != rollingDice && rollingDice2 != 7) //Attempts will be made until the player either rolls the same number or a 7.
        {

            die1 = rand() % 6 + 1;
            die2 = rand() % 6 + 1;
            rollingDice2 = die1 + die2;

            cout << "Player rolled: " << die1 << " + " << die2 << " = " << rollingDice2 << endl << endl;



                if (rollingDice2 == rollingDice)
                    {
                        cout << "You rolled your point! You won!" << endl; // The player matched their number they won.
                    }

                if (rollingDice2 == 7)
                    {
                        cout << "You seven'd out and lost!" << endl; // The player got a total of seven they lost.
                    }

        }

	cin.get();
	return 0;

}
Last edited on
I'm not sure what you ask.

However a note, you have essentially:
1
2
3
4
5
6
7
8
9
10
11
	const int BoxCars = 12; //If the player throws two sixes.
	rollingDice = die1 + die2; //Adds the dice together.
	if ( rollingDice == 12)
        {
            return 0;
        }

        if (rollingDice == BoxCars)
       {
           cout << "Boxcars!" << endl;
       }

IF you roll 12 THEN the game ends immediately
that is ok, but right after you test whether you did roll 12
That can never be true.
Topic archived. No new replies allowed.