Craps Game Program

Ok, so here is the deal.
I found a game of craps in C++ programming from a long time back, but i haven't finished it.
It is too long to fit in a post, so I am going to split it up.
Then I will post the error report.
Then maybe some of you will be able to help me out here!
It would be greatly appreciated.
I used many comments while constructing the program, so that should help.
Here is the first part of the code!:

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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
//Title: craps.cpp
//Name: Norman Gesrtrud
//Date: October 22, 2007
//Description: Plays craps with the user

#include <iostream.h>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <iomanip.h>
#include <ctime>

int rollWhip (void);
int rollBounce (void);
int rollNormal (void);
int houseRoll (void);

int main ()
{
//Declaring Variables
string yn;
int point = 0;
int result = 0;
int cash = 100;
int bet = 0;
int houseResult = 0;
string response;
srand(time(NULL));
enum stat {CON, WIN, LOS};
stat gameStat;
gameStat = CON;

//Idiot proofing - Do/While loop
do
{
   cout << "         ____________   ________       _________       _________     _______
   cout << "        /  _____    /  /  ____  \     /  ____   |     /  _____  \   /  ____/" << endl;
   cout << "       /  /     /  /  /  /   /  /    /  /    |  |    /  /    /  /  /  /     " << endl;
   cout << "      /  /     /  /  /  /___/  /    /  /_____|  |   /  /____/  /  /  /___   " << endl;
   cout << "     /  /     /__/  /    _____/    /  ______    /  /  ________/   \____  \  " << endl;
   cout << "    /  /     __    /  _  \        /  /      /  /  /  /                 \  \ " << endl;
   cout << "   /  /     /  /  /  / \  \      /  /      /  /  /  /                  /  / " << endl;
   cout << "  /  /_____/  /  /  /   \  \    /  /      /  /  /  /            ______/  /  " << endl;
   cout << " /___________/  /__/     \__\  /__/      /__/  /__/            /________/   " << endl;
   cout << "\fCraps v. 4.01 - Based on the game from \"C++ How to Program\""<< endl;
   cout << "\nThis program will play a game of Craps with you." << endl;
   cout << "\nYou will be given $100 to begin with. You may bet up to $50 per roll. You can 
enter $0 to pass" << endl;
   cout << "\nDo you know how to play Craps? [y/n]: ";
   cin >> yn;
}
while (yn != "n" && yn != "N" && yn != "y" && yn != "Y");

//Idiot proofing - Do/While loop, If/Else answer verification
if (yn == "n" || yn == "N")
{
   do
   {
      cout << "\fTwo dice are thrown, if the sum of the two dice is equal to 7 or 11 on the
first toss the player wins. If the sum of the dice are equal to 2, 3, or 12 on
the first toss the house wins (these numbers are called the craps). If the sum
is 4, 5, 6, 8, 9, or 10 for the first toss, the sum rolled becomes the plays
\"point.\" To win the game you must roll your \"point\" again before you roll a sum
of 7, in which case the house wins." << endl;

      cout << "\nAre you ready to play? [y/n]: ";
      cin >> yn;
   }
   while (yn != "y" && yn != "Y" && yn != "n" && yn != "N");
}

//Idiot proofing - Do/While loop, If/Else answer verification
do
{
   if (yn == "y" || yn == "Y")
   {
      string toss;
      string firstToss;

//Idiot proofing - Do/While loop, If/Else answer verification
      do
      {
         cout << "\fPress Ctrl-C to exit this program at anytime." << endl;

         do
         {
            cout << "\nCurrent cash: $" << cash << endl;
            cout << "Enter bet (no more than $50, enter 0 to pass): ";
            cin >> bet;
         }
         while (bet > 50 || bet < 0 && bet < 0 && bet > 50);

         cout << "\nPlease select a rolling technique [1/2/3]: \n\n1. Whip          2. Bounce          3. Normal" << endl;
         cout << "\n[Hint: choose multiple rolling techniques to improve your odds!]" << endl;
         cout << "Enter your rolling technique: ";
         cin >> toss;
         cout << "\f==============================\n\n";

      }
      while (toss != "1" && toss != "2" && toss != "3");

      if (toss == "1")
         result = rollWhip();

      if (toss == "2")
         result = rollBounce();

      if (toss == "3")
         result = rollNormal();

      houseResult = houseRoll();

//Switch statements, first part of quasi-game engine, changes enumerated gameStat value, dependant on first roll
      switch (result)
      {
         case 7:
         case 11:
            gameStat = WIN;
            break;
         default:
            gameStat = CON;
            point = result;
            cout << "\nYour point is " << point << endl;
            break;
      }

      switch (houseResult)
      {
         case 2:
         case 3:
         case 12:
            gameStat = LOS;
            break;
         default:
            break;
      }

//While loop to run game, dependant on the the enumerated gameStat value
      while (gameStat == CON)
      {

         string toss;
         string firstToss;
         int secResult = 0;

//Do/While statement to idiot proof the second and on roll
         do
         {
            cout << "\n\n==============================";
            cout << "\nPress Ctrl-C to quit anytime." << endl;
            cout << "\nCurrent cash: $" << cash << endl;
            cout << "Current bid: $" << bet << endl;
            cout << "\nYour point is " << point << endl;
            cout << "\nPlease select a rolling technique [1/2/3]: \n\n1. Whip          2. Bounce          3. Normal" << endl;
            cout << "\n[Hint: Choose multiple rolling techniques to improve your odds!]" << endl;
            cout << "Enter your rolling technique: ";
            cin >> toss;
            cout << "\f==============================\n\n";

         }
         while (toss != "1" && toss != "2" && toss != "3");

         if (toss == "1")
            secResult = rollWhip();

         if (toss == "2")
            secResult = rollBounce();

         if (toss == "3")
            secResult = rollNormal();

         houseResult = houseRoll();

//If/Else statements, second part of quasi-game engine, changes enumerated gameStat value, dependant on last roll
         if (secResult == point)
            gameStat = WIN;
         else
            gameStat = CON;

         if (houseResult == 7)
            gameStat = LOS;
      }

      if (gameStat == LOS)
         cash -= bet;

      if (gameStat == WIN)
         cash += bet;

      if (gameStat == WIN || gameStat == LOS)
         cout << "\nCurrent cash: " << cash << endl;

//If/Else statements, acts if gameStat declares the game a Win or Loss
      if (gameStat == WIN)
         cout << "Congrats, you win!" << endl;

      if (gameStat == LOS)
         cout << "Hahaha. Fail." << endl;
   } 
   else
   {
      cout << "Play again soon.\n" << endl;
      return 0;
   }

//First part of program Do/While loop to keep playing
   cout << "Would you like to keep playing? [y/n] ";
   cin >> response;

//Idiot proofing - Do/While loop, If/Else answer verification
   if (response != "y" && response != "Y" && response != "n" && response != "N")
      do
      {
         cout << "\n\nIncorrect answer." << endl;
         cout << "\nWould you like to keep playing? [y/n] ";
         cin >> response;
      }
      while (response != "y" || response != "Y" || response != "n" || response != "N");

   if (response == "n" || response == "N")
   {
      cout << "Play again soon.\n" << endl;
      return 0;
   }

//End of program Do/While loop, runs program again if user desires
}
while (response == "y" || response == "Y");
return 0;
}


That is the end of the first part...
Here is the rest of the program....
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

//Function for the players 'Whip' type roll (generates lower numbers)
int rollWhip (void)
{
   int dOne;
   int dTwo;
   int pRoll;
   dOne = 1 + rand() % 5;
   dTwo = 1 + rand() % 5;
   pRoll = dOne + dTwo;
   cout << "\nYou rolled a " << dOne << " and " << dTwo << " for a sum of " << pRoll << endl;
   return pRoll;
}

//Function for the players 'Bounce' type roll (generates higher numbers)
int rollBounce (void)
{
   int dOne;
   int dTwo;
   int pRoll;
   dOne = 2 + rand() % 6;
   if (dOne > 5)
      dOne -= 1;
   dTwo = 2 + rand() % 6;
   if (dTwo > 5)
      dTwo -= 1;
   pRoll = dOne + dTwo;
   cout << "\nYou rolled a " << dOne << " and " << dTwo << " for a sum of " << pRoll << endl;
   return pRoll;
}

//Function for the players 'Normal' type roll (generates regular numbers)
int rollNormal (void)
{
   int dOne;
   int dTwo;
   int pRoll;
   dOne = 1 + rand() % 6;
   dTwo = 1 + rand() % 6;
   pRoll = dOne + dTwo;
   cout << "\nYou rolled a " << dOne << " and " << dTwo << " for a sum of " << pRoll << endl;
   return pRoll;
}

//Function for the houses dice roll, equivalent of players 'Normal' roll 
int houseRoll (void)
{
   int dOne;
   int dTwo;
   int hRoll;
   dOne = 1 + rand() % 6;
   dTwo = 1 + rand() % 6;
   hRoll = dOne + dTwo;
   if (hRoll < 7)
      hRoll += 1;
   if (hRoll > 7)
      hRoll -= 1;
   cout << "The house rolled " << dOne << " and " << dTwo << " for a sum of " << hRoll << endl;
   return hRoll;
}


Ok, now I have an error report here for ya!

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
craps.cpp: In function `int main()':
craps.cpp:38: `_____' undeclared (first use this function)
craps.cpp:38: (Each undeclared identifier is reported only once
craps.cpp:38: for each function it appears in.)
craps.cpp:38: syntax error before `/'
craps.cpp:38: stray '\' in program
craps.cpp:39: stray '\' in program
craps.cpp:45: stray '\' in program
craps.cpp:45: stray '\' in program
craps.cpp:46: stray '\' in program
craps.cpp:47: stray '\' in program
craps.cpp:47: stray '\' in program
craps.cpp:48: stray '\' in program
craps.cpp:48: stray '\' in program
craps.cpp:50: stray '\' in program
craps.cpp:50: stray '\' in program
craps.cpp:52: stray '\' in program
craps.cpp:52: stray '\' in program
craps.cpp:54: stray '\' in program
craps.cpp:54: stray '\' in program
craps.cpp:55: stray '\' in program
craps.cpp:56: stray '\' in program
craps.cpp:57: stray '\' in program
craps.cpp:60: stray '\' in program
craps.cpp:70: stray '\' in program
craps.cpp:78: stray '\' in program
craps.cpp:78: stray '\' in program
craps.cpp:78: stray '\' in program
craps.cpp:78: stray '\' in program
craps.cpp:82: stray '\' in program
craps.cpp:99: stray '\' in program
craps.cpp:104: stray '\' in program
craps.cpp:110: stray '\' in program
craps.cpp:110: stray '\' in program
craps.cpp:110: stray '\' in program
craps.cpp:112: stray '\' in program
craps.cpp:116: stray '\' in program
craps.cpp:116: stray '\' in program
craps.cpp:116: stray '\' in program
craps.cpp:143: stray '\' in program
craps.cpp:169: stray '\' in program
craps.cpp:169: stray '\' in program
craps.cpp:170: stray '\' in program
craps.cpp:171: stray '\' in program
craps.cpp:173: stray '\' in program
craps.cpp:174: stray '\' in program
craps.cpp:174: stray '\' in program
craps.cpp:174: stray '\' in program
craps.cpp:176: stray '\' in program
craps.cpp:180: stray '\' in program
craps.cpp:180: stray '\' in program
craps.cpp:180: stray '\' in program
craps.cpp:214: stray '\' in program
craps.cpp:225: stray '\' in program
craps.cpp:238: stray '\' in program
craps.cpp:238: stray '\' in program
craps.cpp:239: stray '\' in program
craps.cpp:247: stray '\' in program
craps.cpp:266: stray '\' in program
craps.cpp:284: stray '\' in program
craps.cpp:298: stray '\' in program
craps.cpp:320: Unterminated string 
So, there is the Program code, the error report, and I think thats it.
Now, hopefully some of you geniuses will be able to help me out, cause I think it would be awesome to get this working.
I will keep working on it.
Thank you!!!
You are missing " << endl; at the end of line 36 and if you want to draw a '\', you will have to type '\\'
Last edited on
It works now!
Thanks
Topic archived. No new replies allowed.