| | |
Assistance needed with craps game
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Oct 2007
Posts: 4
Reputation:
Solved Threads: 0
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!
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)
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { srand((unsigned)time(NULL)); int firstRoll, nextRoll, die1, die2, sum, gamenum; char playAgain; cout << "Craps game for class" << endl << endl; do { cout << "The game is ready to begin" << endl; cout << endl; die1 = (rand() % 6 + 1); die2 = (rand() % 6 + 1); firstRoll = die1 + die2; gamenum = 1; sum = 0; cout << "Dice1= " << die1 << " and Dice2= " << die2 << " for a total of " << firstRoll << "." << endl; if (firstRoll == 7 || firstRoll == 11) { cout << "Player wins!" << endl; gamenum++; } else if ((firstRoll == 2) || (firstRoll == 3) || (firstRoll == 12)) { cout << "House wins." << endl; gamenum++; } else { do { cout << "Point value is: " << firstRoll << endl; system("pause"); cout << endl; die1 = (rand() % 6 + 1); die2 = (rand() % 6 + 1); nextRoll = die1 + die2; cout << "Dice1= " << die1 << " and Dice2= " << die2 << " for a total of " << nextRoll << "." << endl; if (nextRoll == firstRoll) { cout << "Point value rolled. Player wins" << endl; gamenum = gamenum+1; } else if (nextRoll == 7) { cout << "Player loses" << endl; gamenum = gamenum+1; } else { cout << "Roll again." << endl; system("pause"); cout << endl; } } while ((nextRoll != 7) && (nextRoll != firstRoll)); } while (gamenum<=10000) //Need to focus here because { //Gamenum is not incrementing sum += gamenum; gamenum++; } cout<<gamenum<<endl; cin >> playAgain; if ((playAgain == 'n') || (playAgain == 'N')) { cout << "See ya next time" << endl; } else if ((playAgain == 'y') || (playAgain == 'Y')) { } else { cout << "Please enter either Y or N!" << endl; } //}while; }while ((playAgain == 'y') || (playAgain == 'Y')); }// end of main
Last edited by C++Amanda; Oct 1st, 2007 at 3:40 am.
•
•
Join Date: Oct 2007
Posts: 4
Reputation:
Solved Threads: 0
•
•
•
•
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.
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.
•
•
Join Date: Oct 2007
Posts: 4
Reputation:
Solved Threads: 0
•
•
•
•
>>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.
Please don't shun me just for looking for extra help.
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 **** 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.
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 **** 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.
>>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
Replace the do loop with a for loop
C++ Syntax (Toggle Plain Text)
for(int i = 0; i < 1000; i++) { // blabla }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Oct 2007
Posts: 4
Reputation:
Solved Threads: 0
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.
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.
>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 **** 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.
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 **** 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.
I'm here to prove you wrong.
>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.
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.
*Voted best profile in the world*
![]() |
Similar Threads
- Programmers needed for game dev. team (Software Development Job Offers)
- Need some Help with PHP Craps game! (PHP)
- Craps, game help! (C++)
- PHP coder needed for online game (Web Development Job Offers)
- C craps game (C)
- I receive this message when trying to play a video game. (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: Help with 'While' Structure
- Next Thread: how to expand arrays
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






