New Craps Game

Pages: 12
I'm an amateur user of C++ so bear with me if my code offends you in some fashion.
I'm developing a craps game....
Towards the end of the program I would like it to have uppercase input of Y or N when it asks if I want to play again.
I'd rather not have it lower case, so maybe a warning message might spit out if you input a lowercase y or n.
Unfortunately my knowledge of C++ only stretches so far...
Whenever I replay the game it never updates the amount of money I have left.
If I run out of money it never tells me to exit the program.
I would like to input all of this data into an external file which would be nice.


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
#include <iostream>
#include<cstdlib>
#include<iomanip>
#include "rolldice.cpp"


using namespace std;

int main()
{
char choice = 'Y';
const int LUCKY_SEVEN = 7,
           CRAPS = 7,
           YO_LEVEN = 11,
           SNAKE_EYES = 2,
           TREY = 3,
           BOX_CARS = 12;
           
   
   const double MINIMUM = 500.00;
void rolldice(int& die1, int& die2);   

           
   int die1, die2, dieSum, point;
   bool won, quit;
   double purse, bet;
   double seed1;
   double seed2;
   int random(double seed1);
   int random(double seed2);
   
  

 

 cout<<"This program will simulate the game of craps and will allow you to bet\n"
       <<"a certain amount of money. Based on your roll, you will win or lose money.\n"
       <<"If on your first roll, you roll a 7 or an 11, you will win (Craps Out!)\n"
       <<"Until you Crap Out, you will continue to roll. Your starting amount of\n"
       <<"money is $1000. You will win or loose money based upon what you have\n"
       <<"wagered. Good luck!.\n\n";
       
cout<<"You have 1000 dollars, you will be asked to place a bet until\n"
    <<"you run out.\n";       
  do
  {
   double seed1;
   double seed2;
   int random(double seed1);
   int random(double seed2);
   purse=1000;
{   
if(purse==0)
cout<<"Please exit the game and restart, you do not have enoough money left...\n";

}   
if(dieSum==false)

cout<<"You have "<<purse-bet<<"dollars left!\n";

else if(dieSum==true)
cout<<"You have "<<purse+bet<<"dollars left!\n";


cout<<"Please enter a valid bet, bet must be greater or equal to $500.\n";
cin>>bet;

{
if (bet>=500)

cout<<"Let us start by rolling the dice...\n";

else if  (bet<500)

cout<<"The minimum bet is $500, please enter a value greater than 500. \n";
}

cout<<"Enter a three values seperated by a space between 0 and 1 to simulate\n"
    <<"the roll of the two dice:\n\n";
cin>>seed1>>seed2;
die1= random(seed1);
die2= random(seed2);
dieSum=(die1+die2);


cout<<"You rolled a "<<die1<<" & "<<die2<<"which adds up to "<<dieSum<<"!\n\n";


const int LUCKY_SEVEN = 7,
           CRAPS = 7,
           YO_LEVEN = 11,
           SNAKE_EYES = 2,
           TREY = 3,
           BOX_CARS = 12;
switch(dieSum)
{
case LUCKY_SEVEN:
     YO_LEVEN:  won = true;
     break;
case SNAKE_EYES:
     TREY:
     BOX_CARS: won = false;
     break;
     default: point = dieSum;
     cout<<"Your point becomes your dieSum\n\n";


if (dieSum==true)
{
purse+=bet;
cout<<"You win "<< bet <<" dollars, you now have "<< purse + bet <<" !\n\n";
}

else if  (dieSum=false)
purse-=bet;
cout<<"You lose "<< bet <<" you now have "<< purse - bet <<" !\n\n";
}
  // You probably only need one do while or while loop here so there can
 do
     {
       cout<<"Would you like to play again?\n";
       cin>>choice;
       choice = toupper(choice);
       if(choice !='Y' && choice != 'N')
         cout<<"Illegal response! Please answer Y for Yes or N for No!\n";
     }while(choice != 'Y' && choice != 'N');
     if(choice=='N')
        //quit
     else(choice=='Y')
        cout<<"Ok then...\n";

}
       
while( (choice!='Y') && (choice!='N'))

 return 0;
} 

In order for the program to work, it needs these two other programs included:


Rolldice.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "random.cpp"
#include<iostream>
using namespace std;

void rolldice(int& die1, int& die2)
{
   int random(double seed);
   
   double seed1, seed2;
   do
   {
     cout<<"\n\nEnter two seed values between 0 and 1, separated by a space,\n";
     cout<<"and then press ENTER to simulate the rolling of a pair of dice.\n";
     cin>>seed1>>seed2;
     if(seed1<0 || seed1>1 || seed2<0 ||seed2>1)
       cout<<"Seed values must be between 0 and 1!\n";
   }while(seed1<0 || seed1>1 || seed2<0 ||seed2>1);
   
   die1 = random(seed1);
   die2 = random(seed2);
   return;
}



Random.cpp
1
2
3
4
5
6
7
8
#include<cmath>

int random(double seed)
{
    seed = static_cast<double>(pow(seed+3.14,2));
    seed = seed - static_cast<int>(seed);
    return 1 + static_cast<int>(6 * seed);
}


Thank you in advanced for any helpful suggestions, I'm really starting to hate this game of Craps.
Last edited on
You should really have just added this to the bottom of the last thread, that way the people who can help you have the entire story, and you won't be getting the same responses that you got before.
Sorry I should have done that, sometimes people don't respond back to me. Is there any way to help me somebody.
Last edited on
Convert the character to upper case. After you take in the input add this
input_value = toupper(input_value);

toupper is a function of <cctype> so make sure you include it at the top.

I have rewritten some of the code:

main.cpp
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
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <iomanip>
#include "rolldice.cpp"

using namespace std;


int main()
{
	char choice = 'Y';
	const int LUCKY_SEVEN = 7,
		CRAPS = 7,
		YO_LEVEN = 11,
		SNAKE_EYES = 2,
		TREY = 3,
		BOX_CARS = 12;
           
	
	const double MINIMUM = 500.00;
	
           
	int die1, die2, dieSum, point;
	bool won, quit;
	double purse = 1000, bet = 0;
 

	cout << "This program will simulate the game of craps and will allow you to bet\n"
		<< "a certain amount of money. Based on your roll, you will win or lose money.\n"
        << "If on your first roll, you roll a 7 or an 11, you will win (Craps Out!)\n"
        << "Until you Crap Out, you will continue to roll. Your starting amount of\n"
        << "money is $1000. You will win or loose money based upon what you have\n"
        << "wagered. Good luck!.\n\n";
       
	cout << "You have 1000 dollars, you will be asked to place a bet until\n"
		<< "you run out.\n";       
	
	
	// main game loop
	do
	{
		
		// new game
		purse = 1000;
		
		
		if(purse==0)
		{
			cout<<"Exiting game now...\nYou do not have enough money left...\n";
			return 0;
		}

		if(dieSum == false)
		{
			cout<< "You have " << purse - bet << "dollars left!\n";
		}
		else if(dieSum == true)
		{
			cout << "You have " << purse + bet << "dollars left!\n";
		}

		cout << "Please enter a valid bet, bet must be greater or equal to $500.\n";
		cin >> bet;


		if(bet >= 500)
		{
			cout<<"Let us start by rolling the dice...\n";
		}
		else if(bet<500)
		{
			cout<<"The minimum bet is $500, please enter a value greater than 500. \n";
		}

		// Roll the dice
		rolldice(die1, die2);
		dieSum = die1 + die2;

		cout << "You rolled a " << die1 << " & " << die2 << " which adds up to " << dieSum << "!\n\n";



		switch(dieSum)
		{
			case LUCKY_SEVEN:
			case YO_LEVEN:  
				won = true;
			break;
			
			case SNAKE_EYES:
			case TREY:
			case BOX_CARS: 
				won = false;
			break;
		    
			default: 
				point = dieSum;
				cout << "Your point becomes your dieSum\n\n";
		}

		if(won==true)
		{
			purse += bet;
			cout<< "You win " << bet << " dollars, you now have " << purse + bet << " !\n\n";
		}

		else if(dieSum=false)
		{
			purse-=bet;
			cout << "You lose " << bet << " you now have " << purse - bet << " !\n\n";
		}
		 

		while(true)
		{
			cout<<"Would you like to play again?\n";
			cin>>choice;
			
			choice = toupper(choice);
			
			if( (choice !='Y') || (choice != 'N') )
			{
				cout<<"Illegal response! Please answer Y for Yes or N for No!\n";
			}
			else
			{
				// Go to the main game loop and decide what to do
				break;
			}

		}
			

	}while( choice == 'Y');

	
	return 0;
} 


rolldice.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include "random.h"

using namespace std;

void rolldice(int& die1, int& die2)
{
   cout << "Rolling the dice...\n";
   
   die1 = random();
   die2 = random();

   return;
}


random.cpp
1
2
3
4
5
6
7
8
9
#include <cstdlib>

// Generate a random #
int random()
{
	int die_number; // 1-6, the number on a die
	die_number = rand() % 6 + 1;
	return die_number;
}


You cannot use dieSum at an integer and also as a boolean value. You need to have it one or the other. In this case it should be an integer. ( I didn't fix all of the if's were diceSum was being compared against a boolean value )

In my opinion the whole game loop needs to be rewritten. You are not understanding function calls and prototypes. All of your function calls were actually function prototypes.

Study that code and look at the improvements I made to it.
You also need another loop inside the main game loop so the player can keep on betting.

You should learn to to space and indent your code consistently. It is terrible on the eyes trying to read it other wise. Also post in code tags
Last edited on
When I tried to do an else statement at line 129 of yours, it wouldn't allow me. So I took it out but whenever I input Y it reads out illegal response.
That doesn't even compile so I don't know how your testing it. The else works.

What compiler/IDE do you use?
I'm using bloodshed. If that was what your asking.
Yeah.

In line 108 (In the code I posted)

Change dieSum to won.


Delete lines 54 and 61. They are unneccesary.
Basically i'm trying to rolldice and based of the number I roll I win or lose money, then if I want to loop the game I will have a different purse value based on the amount of money I've won or lost.
Okay, add a while loop on line 46 like this:
1
2
3
while(purse > 0)
{
//... 


Place the ending brace on line 113 (After the "you win/lose" if statements)

Then delete the if statement at line 48 - 52.

Also in the win/lose ifs:
This line:
cout<< "You win " << bet << " dollars, you now have " << purse + bet << " !\n\n";

Should be changed to this:
cout<< "You win " << bet << " dollars, you now have " << purse << " !\n\n";

You need to delete the "+bet" or "-bet" because the purse was already calculated.
Last edited on
Ok so I've added some changes to this program. But when I roll the dice it doesn't tell me whether I've won or not based off the switch statement. It also doesn't tell me my total amount in my purse. I'll try a couple of things right now. But....


Here is what changes I've made that I believe you told me to do:


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
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <iomanip>
#include "rolldice.cpp"

using namespace std;


int main()
{
	char choice = 'Y';
	const int LUCKY_SEVEN = 7,
		CRAPS = 7,
		YO_LEVEN = 11,
		SNAKE_EYES = 2,
		TREY = 3,
		BOX_CARS = 12;
           
	
	const double MINIMUM = 500.00;
	
           
	int die1, die2, dieSum, point;
	bool won, quit;
	double purse = 1000, bet = 0;
 

	cout << "This program will simulate the game of craps and will allow you to bet\n"
		<< "a certain amount of money. Based on your roll, you will win or lose money.\n"
        << "If on your first roll, you roll a 7 or an 11, you will win (Craps Out!)\n"
        << "Until you Crap Out, you will continue to roll. Your starting amount of\n"
        << "money is $1000. You will win or loose money based upon what you have\n"
        << "wagered. Good luck!.\n\n";
       
	cout << "You have 1000 dollars, you will be asked to place a bet until\n"
		<< "you run out.\n";       
	
	
	// main game loop
	do
	{
		
		// new game
		purse = 1000;
		while(purse>0)
		
	{	
		

		if(dieSum == false)
		{
			cout<< "You have " << purse - bet << "dollars left!\n";
		}
		else if(dieSum == true)
		{
			cout << "You have " << purse + bet << "dollars left!\n";
		}

		cout << "Please enter a valid bet, bet must be greater or equal to $500.\n";
		cin >> bet;


		if(bet >= 500)
		{
			cout<<"Let us start by rolling the dice...\n";
		}
		else if(bet<500)
		{
			cout<<"The minimum bet is $500, please enter a value greater than 500. \n";
		}

		// Roll the dice
		rolldice(die1, die2);
		dieSum = die1 + die2;

		cout << "You rolled a " << die1 << " & " << die2 << " which adds up to " << dieSum << "!\n\n";



		switch(dieSum)
		{
			case LUCKY_SEVEN:
			case YO_LEVEN:  
				won = true;
			break;
			
			case SNAKE_EYES:
			case TREY:
			case BOX_CARS: 
				won = false;
			break;
		    
			default: 
				point = dieSum;
				cout << "Your point becomes your dieSum\n\n";
		}

		if(won==true)
		{
			purse += bet;
			cout<< "You win " << bet << " dollars, you now have " << purse  << " !\n\n";
		}

		else if(won=false)
		{
			purse-=bet;
			cout << "You lose " << bet << " you now have " << purse << " !\n\n";
		}
}	 

		while(true)
		{
			cout<<"Would you like to play again?\n";
			cin>>choice;
			
			choice = toupper(choice);
			
			if( (choice !='Y') || (choice != 'N') )
			{
				cout<<"Illegal response! Please answer Y for Yes or N for No!\n";
			}
			else
			{
				// Go to the main game loop and decide what to do
				break;
			}

		}

			

	}while( choice == 'Y');
if(won==true)
		{
			purse += bet;
			cout<< "You win " << bet << " dollars, you now have " << purse + bet << " !\n\n";
		}

		else if(dieSum=false)
		{
			purse-=bet;
			cout << "You lose " << bet << " you now have " << purse - bet << " !\n\n";
		}
	
	return 0;
} 
It actually doesn't tell me if I've lost money, and sometimes it will tell me if I've won... So say if I entered a value like .555 and .55, I usually win and it will tell me I have $1500 then. But I don't think think it will tell me that I have zero dollars left and that I should re-enter the game. Thats what I would like to do.
Ok, so It actually tells me that I've won a certain amount of money, but it won't ask me If I want to play again, I would like it if the program did ask me that at the end of each round. It still doesn't tell me whether I've lost any money though.
Ok, so I fixed the part regarding the game not telling me what I've lost. But now when it does ask me If I want to play again, it only asks me after I have no money left. I would like it to ask me whether I want to play again after every round that I play regardless of winning or losing. Also, when I do in fact run out of money, the program does ask me If I want to play again, but when I type Y for yes, it responds by saying illegal response.
Isn't asking the user after they lose all of their money the point? Your not going to ask them after every bid.
Well, ok. But when I run out of money and it asks me if I want to play again it won't display the message "You have ran out of money please re-enter the program." It doesn't display that message over and over which I would like it to do. Also, when inputting lowercase y after it asks me if I want to play, doesn't display, Illegal response. Here is what I have managed to do so far now:


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
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <iomanip>
#include "rolldice.cpp"

using namespace std;


int main()
{
	char choice = 'Y';
	const int LUCKY_SEVEN = 7,
		CRAPS = 7,
		YO_LEVEN = 11,
		SNAKE_EYES = 2,
		TREY = 3,
		BOX_CARS = 12;
           
	
	const double MINIMUM = 500.00;
	
           
	int die1, die2, dieSum, point;
	bool won, quit;
	double purse = 1000, bet = 0;
 

	cout << "This program will simulate the game of craps and will allow you to bet\n"
		<< "a certain amount of money. Based on your roll, you will win or lose money.\n"
        << "If on your first roll, you roll a 7 or an 11, you will win (Craps Out!)\n"
        << "Until you Crap Out, you will continue to roll. Your starting amount of\n"
        << "money is $1000. You will win or loose money based upon what you have\n"
        << "wagered. Good luck!.\n\n";
       
	cout << "You have 1000 dollars, you will be asked to place a bet until\n"
		<< "you run out.\n";       
	
	
	// main game loop
	do
	{
		
		// new game
		purse = 1000;
		while(purse>0 && purse!=0)
		
	{	
		

		if(dieSum == false)
		{
			cout<< "You have " << purse  << "dollars left!\n";
		}
		else if(dieSum == true)
		{
			cout << "You have " << purse  << "dollars left!\n";
		}
        if (purse>0 && purse!=0)
		cout << "Please enter a valid bet, bet must be greater or equal to $500.\n";
		cin >> bet;
        

		if(bet >= 500)
		{
			cout<<"Let us start by rolling the dice...\n";
		}
		else if(bet<500)
		{
			cout<<"The minimum bet is $500, please enter a value greater than 500. \n"
			    <<"Please re-enter a valid bet:\n";
			    cin>>bet;
		}

		// Roll the dice
		rolldice(die1, die2);
		dieSum = die1 + die2;

		cout << "You rolled a " << die1 << " & " << die2 << " which adds up to " << dieSum << "!\n\n";



		switch(dieSum)
		{
			case LUCKY_SEVEN:
			case YO_LEVEN:  
				won = true;
			break;
			
			case SNAKE_EYES:
			case TREY:
			case BOX_CARS: 
				won = false;
			break;
		    
			default: 
				point = dieSum;
				cout << "Your point becomes your dieSum\n\n";
		}

		if(won==true)
		{
			purse += bet;
			cout<< "You win " << bet << " dollars, you now have " << purse  << " !\n\n";
		}

		else if(won==false)
		{
			purse-=bet;
			cout << "You lose " << bet << " you now have " << purse << " !\n\n";
		}
		
       
}	 

		while(true)
		{
            
             if(purse!=0)
			cout<<"Would you like to play again?\n";
			cin>>choice;
			
			choice = toupper(choice);
			if(purse==0)
            {
			cout<<"Please re-enter the program, you do not have any cash left..\n";
			break;
        }
			 if((choice ='Y') || (choice = 'N'))
			{
				cout<<"Illegal response! Please answer Y for Yes or N for No!\n"
				    <<"Please enter a valid Y or N.\n";
				    cin>>choice;
				
			  if (choice=='Y')
			{
                cout<<"\nHere we go again...\n";
                break;
              
                } 
			 
			}
			 
			
				
          }

		

			

	}while( choice == 'Y' && choice!='N');

	
	return 0;
} 
Wait I think I got that fixed, I put in:

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
	while(true)
		{
            if (purse==0)
            cout<<"Please re-enter the game, you do not have enough cash!\n";
            
            
             else if(purse!=0)
			cout<<"Would you like to play again?\n";
			cin>>choice;
			
			choice = toupper(choice);
			
        
		  if((choice ='Y') || (choice = 'N'))
			{
				cout<<"Illegal response! Please answer Y for Yes or N for No!\n"
				    <<"Please enter a valid Y or N.\n";
				    cin>>choice;
				
			  if (choice=='Y')
			{
                cout<<"\nHere we go again...\n";
                break;
              
                } 
			 
			}
			 
			
				
          } 

Does that look alright??
Last edited on
Nope. Notice your if statments. Their are assignments, not comparisons.

I fixed the code as best I could. It is fully functional.

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
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <iomanip>
#include "rolldice.h"

using namespace std;


int main()
{
	char choice = 'Y';
	const int LUCKY_SEVEN = 7,
		CRAPS = 7,
		YO_LEVEN = 11,
		SNAKE_EYES = 2,
		TREY = 3,
		BOX_CARS = 12;
           
	
	const double MINIMUM = 500.00;
	
           
	int die1 = 0, die2 = 0, dieSum = 0, point = 0;
	
	double purse = 1000.0, bet;
 

	cout << "This program will simulate the game of craps and will allow you to bet\n"
		<< "a certain amount of money. Based on your roll, you will win or lose money.\n"
        << "If on your first roll, you roll a 7 or an 11, you will win (Craps Out!)\n"
        << "Until you Crap Out, you will continue to roll. Your starting amount of\n"
        << "money is $1000. You will win or loose money based upon what you have\n"
        << "wagered. Good luck!.\n\n";
       
	cout << "You have 1000 dollars, you will be asked to place a bet until\n"
		<< "you run out.\n";       
	
	
	// main game loop
	do
	{
		
		// new game
		purse = 1000;
		bet = 0;
		
		
		
		while( purse > 0 )
		{			
			cout<< "\nYou have " << purse << " dollars left!\n\n";
			

			// Prompt the user for a bet
			while(true)
			{
				
				cout << "Please enter a valid bet, bet must be greater or equal to $500.\n";
				cin >> bet;


				if(bet >= 500)
				{
					cout << "Let us start by rolling the dice...\n";
					break;
				}
				else if(bet<500)
				{
					cout<<"The minimum bet is $500, please enter a value greater than 500. \n";
				}
			}

			// Roll the dice
			rolldice(die1, die2);
			dieSum = die1 + die2;

			cout << "You rolled a " << die1 << " & " << die2 << " which adds up to " << dieSum << "!\n\n";


			switch(dieSum)
			{
				case LUCKY_SEVEN:
				case YO_LEVEN:  
					
					purse += bet;
					cout<< "You win " << bet << " dollars, you now have " << purse << " !\n\n";

				break;
				
				case SNAKE_EYES:
				case TREY:
				case BOX_CARS: 
					
					purse-=bet;
					cout << "You lose " << bet << " you now have " << purse << " !\n\n";

				break;
			    
				default: 
					point = dieSum;
					cout << "Your point becomes your dieSum\n\n";
			}
		
		
		}	// end of while betting loop

		while(true)
		{
			cout<<"Would you like to play again?\n";
			cin>>choice;
			
			choice = toupper(choice);
			
			if( (choice =='Y') || (choice == 'N') )
			{
				break;
			}
			else
			{
				// Go to the main game loop and decide what to do
				cout<<"Illegal response! Please answer Y for Yes or N for No!\n";
			}

		}
			

	}while( choice == 'Y');

	
	return 0;
} 


This uses my version of the rolldice and random. (Not your seed stuff)

Btw I suggest that you download Visual C++ Express and debug your code if there are little errors. It saves time and you can pinpoint errors.
Last edited on
If I wanted everything put onto an external .txt file how might that look, or is that pushing the limit??
I think I got the code to output it to an external .txt file, is this right..:

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
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <iomanip>
#include "rolldice.cpp"
#include<fstream>
using namespace std;


int main()
{
	char choice = 'Y';
	const int LUCKY_SEVEN = 7,
		CRAPS = 7,
		YO_LEVEN = 11,
		SNAKE_EYES = 2,
		TREY = 3,
		BOX_CARS = 12;
           
	
	const double MINIMUM = 500.00;
	
           
	int die1 = 0, die2 = 0, dieSum = 0, point = 0;
	
	double purse = 1000.0, bet;
	
    ofstream outs;
    
    outs.open("craps1.txt",ios::app); 

	cout << "This program will simulate the game of craps and will allow you to bet\n"
		<< "a certain amount of money. Based on your roll, you will win or lose money.\n"
        << "If on your first roll, you roll a 7 or an 11, you will win (Craps Out!)\n"
        << "Until you Crap Out, you will continue to roll. Your starting amount of\n"
        << "money is $1000. You will win or loose money based upon what you have\n"
        << "wagered. Good luck!.\n\n";
       
	cout << "You have 1000 dollars, you will be asked to place a bet until\n"
		<< "you run out.\n";       

	
	// main game loop
	do
	{
		
		// new game
		purse = 1000;
		bet = 0;
		
		
		
		while( purse > 0 )
		{			
			cout<< "\nYou have " << purse << " dollars left!\n\n";
			outs<< left << "\nYou have " << purse << " dollars left!\n\n";

			// Prompt the user for a bet
			while(true)
			{
				
				cout << "Please enter a valid bet, bet must be greater or equal to $500.\n";
				cin >> bet;
				


				if(bet >= 500)
				{
					cout << "You have bet "<< bet <<" let us start by rolling the dice...\n";
					break;
					outs << "You have bet "<< bet <<" let us start by rolling the dice...\n";
					break;
				}
				else if(bet<500)
				{
					cout<<"The minimum bet is $500, please enter a value greater than 500. \n";
					
				}
			}

			// Roll the dice
			rolldice(die1, die2);
			dieSum = die1 + die2;

			cout << "You rolled a " << die1 << " & " << die2 << " which adds up to " << dieSum << "!\n\n";
            outs << left << "You rolled a " << die1 << " & " << die2 << " which adds up to " << dieSum << "!\n\n";

			switch(dieSum)
			{
				case LUCKY_SEVEN:
				case YO_LEVEN:  
					
					purse += bet;
					cout<< "You win " << bet << " dollars, you now have " << purse << " !\n\n";
                    outs<< left << "You win " << bet << " dollars, you now have " << purse << " !\n\n";
				break;
				
				case SNAKE_EYES:
				case TREY:
				case BOX_CARS: 
					
					purse-=bet;
					cout << "You lose " << bet << " you now have " << purse << " !\n\n";
                    outs << left << "You lose " << bet << " you now have " << purse << " !\n\n";
				break;
			    
				default: 
					point = dieSum;
					cout << "Your point becomes your dieSum\n\n";

			}
		
		
		}	// end of while betting loop

		while(true)
		{
			cout<<"Would you like to play again?\n";
			cin>>choice;
			
			choice = toupper(choice);
			
			if( (choice =='Y') || (choice == 'N') )
			{
				break;
			}
			else
			{
				// Go to the main game loop and decide what to do
				cout<<"Illegal response! Please answer Y for Yes or N for No!\n";
			
			}

		}
			

	}while( choice == 'Y');
	
    outs.close(); 
	
	return 0;
}
Last edited on
Pages: 12