943,769 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 3708
  • C++ RSS
Oct 1st, 2007
0

Assistance needed with craps game

Expand Post »
I am very new to C++. I have to write a program for class that reflects the game of craps and I'm kinda stuck at this point. Any help someone could give me would be HUGELY appreciated.
The guidelines we were given are that the program should execute 10000 times to compute the probability of the "player" winning and the "house" winning.

Basic game rules are:
Player rolls two dice.
When the sum is 7 or 11 on first throw, player wins.
When the sum is 2, 3, or 12 on first throw, "house" wins.
When the sum is 4,5,6,8,9, or 10 on first throw, that sum becomes the player's "point".
Now, to win the player must continue rolling the dice until he makes "point"; however should he roll a 7 then the "house" wins.
The game ends.

My code this far is below. It seems as if my game counter is not updating. Also, how can I make this automated to run the 10000 times without myself having to push the Y or N keys? Thanks to whoever helps me!

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. srand((unsigned)time(NULL));
  9.  
  10. int firstRoll, nextRoll, die1, die2, sum, gamenum;
  11. char playAgain;
  12.  
  13. cout << "Craps game for class" << endl << endl;
  14.  
  15. do
  16. {
  17. cout << "The game is ready to begin" << endl;
  18. cout << endl;
  19.  
  20. die1 = (rand() % 6 + 1);
  21. die2 = (rand() % 6 + 1);
  22. firstRoll = die1 + die2;
  23. gamenum = 1;
  24. sum = 0;
  25.  
  26. cout << "Dice1= " << die1 << " and Dice2= " << die2 << " for a total of " << firstRoll << "." << endl;
  27.  
  28. if (firstRoll == 7 || firstRoll == 11)
  29. {
  30. cout << "Player wins!" << endl;
  31. gamenum++;
  32. }
  33.  
  34. else if ((firstRoll == 2) || (firstRoll == 3) || (firstRoll == 12))
  35. {
  36. cout << "House wins." << endl;
  37. gamenum++;
  38. }
  39.  
  40. else
  41. {
  42. do
  43. {
  44. cout << "Point value is: " << firstRoll << endl;
  45. system("pause");
  46. cout << endl;
  47.  
  48. die1 = (rand() % 6 + 1);
  49. die2 = (rand() % 6 + 1);
  50. nextRoll = die1 + die2;
  51.  
  52. cout << "Dice1= " << die1 << " and Dice2= " << die2 << " for a total of " << nextRoll << "." << endl;
  53.  
  54. if (nextRoll == firstRoll)
  55. {
  56. cout << "Point value rolled. Player wins" << endl;
  57. gamenum = gamenum+1;
  58. }
  59.  
  60. else if (nextRoll == 7)
  61. {
  62. cout << "Player loses" << endl;
  63. gamenum = gamenum+1;
  64. }
  65.  
  66. else
  67. {
  68. cout << "Roll again." << endl;
  69. system("pause");
  70. cout << endl;
  71. }
  72. }
  73. while ((nextRoll != 7) && (nextRoll != firstRoll));
  74. }
  75.  
  76. while (gamenum<=10000) //Need to focus here because
  77. { //Gamenum is not incrementing
  78. sum += gamenum;
  79. gamenum++;
  80. }
  81. cout<<gamenum<<endl;
  82. cin >> playAgain;
  83.  
  84. if ((playAgain == 'n') || (playAgain == 'N'))
  85. {
  86. cout << "See ya next time" << endl;
  87. }
  88.  
  89. else if ((playAgain == 'y') || (playAgain == 'Y'))
  90. {
  91. }
  92.  
  93. else
  94. {
  95. cout << "Please enter either Y or N!" << endl;
  96. }
  97. //}while;
  98. }while ((playAgain == 'y') || (playAgain == 'Y'));
  99. }// end of main
Last edited by C++Amanda; Oct 1st, 2007 at 3:40 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
C++Amanda is offline Offline
4 posts
since Oct 2007
Oct 1st, 2007
0

Re: Assistance needed with craps game

Also posted on cprogramming.com.
Just so you know, seeing the same post on multiple forums doesn't look good to a lot of people.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Oct 1st, 2007
0

Re: Assistance needed with craps game

Click to Expand / Collapse  Quote originally posted by Salem ...
Also posted on cprogramming.com.
Just so you know, seeing the same post on multiple forums doesn't look good to a lot of people.
Why doesn't it look good?
So, trying to get help anywhere I can is a bad thing? I'm having trouble with a program and am asking for help.
Last edited by C++Amanda; Oct 1st, 2007 at 9:45 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
C++Amanda is offline Offline
4 posts
since Oct 2007
Oct 1st, 2007
0

Re: Assistance needed with craps game

>>Why doesn't it look good?
Because why should I bother to answer here when you might already get answers elsewhere, and you might get conflicting answers at that.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Oct 1st, 2007
0

Re: Assistance needed with craps game

>>Why doesn't it look good?
Because why should I bother to answer here when you might already get answers elsewhere, and you might get conflicting answers at that.
Well, I understand the concern with receiving conflicting answers elsewhere, but I don't see what it matters where else I get answers. It should be up to me to decide what to do with conflicting answers. I see you guys' point but I hope you also see mine: I need help so I'm looking everywhere for it.
Please don't shun me just for looking for extra help.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
C++Amanda is offline Offline
4 posts
since Oct 2007
Oct 1st, 2007
0

Re: Assistance needed with craps game

I read multiple posts as this
http://catb.org/~esr/faqs/smart-questions.html#urgent

You can't be bothered to see if one forum pans out and gives you the answer you need, so you decide to spam a whole bunch of forums and you don't give a damn how many people you piss off in the process so long as you get what you want.

In other words, how is this different from a spammer selling snake oil, it doesn't matter to them so long as some schmuck hands over the money.

http://catb.org/~esr/faqs/smart-questions.html#forum is another point to ponder.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Oct 1st, 2007
0

Re: Assistance needed with craps game

>>how can I make this automated to run the 10000 times without myself having to push the Y or N keys?

Replace the do loop with a for loop
C++ Syntax (Toggle Plain Text)
  1. for(int i = 0; i < 1000; i++)
  2. {
  3. // blabla
  4. }
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Oct 1st, 2007
0

Re: Assistance needed with craps game

Click to Expand / Collapse  Quote originally posted by Salem ...
I read multiple posts as this
...
Salem,
I'm not trying to upset anyone. I'm only trying to get some assistance. If you really feel that I'm acting like a spammer then I'll leave and not come back. I don't have time for this drama. I never thought I'd catch this kind of flak for asking for help.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
C++Amanda is offline Offline
4 posts
since Oct 2007
Oct 1st, 2007
0

Re: Assistance needed with craps game

>Why doesn't it look good?
Because a lot of us visit most of those forums, and seeing an identical thread on each one reeks of spamming and trolling for answers.

>I don't see what it matters where else I get answers.
It doesn't matter. What matters is that by asking us, then asking another forum, you're basically saying that you don't trust our answers. On top of being insulted like that, those of us that visit all of the forums in question are going to be irritated by having to pick which forum to help you on for maximum effect. That's a lot of work, and while I can't speak for Salem, I'm not willing to go to that kind of effort just to help some faceless net junkie. Also keep in mind that the most qualified helpers are going to be members of most, if not all, of those forums. By alienating us, you risk losing the highest quality answers.

>If you really feel that I'm acting like a spammer then I'll leave and not come back.
Okay. We don't care if you stay or go. That's completely your decision, regardless of how much you try to focus the blame on other people. Throwing out an ultimatum just makes you look like you're starved for attention.

>I don't have time for this drama. I never thought I'd catch this kind of flak for asking for help.
Salem is trying to help you. If you piss off the people you're asking for help from, you waste much more time than dealing with the "drama" because they'll simply refuse to help you. So don't give us the wounded little kid routine. It doesn't work. Just accept the criticism and learn from it.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Oct 1st, 2007
0

Re: Assistance needed with craps game

>Also, how can I make this automated to run the 10000 times without myself having to push the Y or N keys

You could employ a malnourished Ethiopian for less than a fiver to hit the 'y' key 10,000 times. The money accrued would help feed him and his family for weeks.
Last edited by iamthwee; Oct 1st, 2007 at 3:16 pm.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Help with 'While' Structure
Next Thread in C++ Forum Timeline: how to expand arrays





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC