### Dice Game Problem

Hello. I have been designing a dice game program that calls for a playet to roll seven dice, each of which results in a value 1 through 6.
The scoring should be that:
-A triple (any 3 or more dice with identical values) scores 100 times the face value
except for three ones which score as 1,000 points.

-If two triples are scored, the score will be 150 times the face value of each,
except for three ones which score as 900 points.

then if no triple is rolled, then each “1" scores 100 points and/or each "5" scores 50 points.

-The game ends when one player scores 10,000 or more points. However, all players should
be able to complete the last turn, and therefore more than one player could score over 10,000 points. The player with the highest score wins. If more than one player matches high
score, it is a tie.

This is what i came up with Im not sure how to apply the scoring method at the end of seven runs. Your input is greatly appreciated

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124`` ``````#include #include #include using namespace std; int dice1, dice2 = 0; void RollDice(); // The Void Program That Rolls The Dice int main() { srand(time(0)); int input = 1; do { if (input == 1) { system ("Pause"); RollDice(); // Function That Does Everything For The Code cout << " Press 1 to Roll and 2 to Quit :"; } else if (input !=1 || input != 2) { cout << "Input Again:"<> input; } while(input!=2); return 1; } void RollDice() { dice1 = (rand()%6+1); // 1-6 Numbers dice2 = (rand()%6+1); // To Make It Different It Multiplies By 13 switch(dice1) //Switch Statement That Has All The Possible Outcomes For Dice 1 { case 1: cout <<"player 1"<
Last edited on
Put your code in a code tag. It formats it and makes it readable. It's the <> button on the right side of the text box.
ok there it is
Also use proper indentation. It makes reading long stuff like your big do while loop at the top much easier. Also you could make your output player switch cases at the bottom a single while loop like so
`cout << "PLayer " << counter << endl;`

that'll get rid of a good 40 lines. also you can put all your couts on one line
Im not sure what you mean. Is it that i should start the `cout << "PLayer " << counter << endl;` at the beginning of the do statement?
No. What I mean is that you have two very long pieces of similar code, so you should always try and wrap them together to make it easier to read. Something like this:
 ``12345678910111213141516171819202122232425262728293031`` ``````int counter = 1 while(counter <= 2) { switch(dice1) //Switch Statement That Has All The Possible Outcomes For Dice 1 { case 1: cout <<"player "<< counter << endl << endl << "[ . ] " << endl; break; case 2: cout <<"player "<< counter << endl << endl << "[ : ] " << endl; break; case 3: cout <<"player "<< counter << endl << endl << "[. :] " << endl; break; case 4: cout <<"player "<< counter << endl << endl << "[: :] " << endl; break; case 5: cout <<"player "<< counter << endl << endl << "[:.:] " << endl; break; case 6: cout <<"player "<< counter << endl << endl << "[:::] " << endl; break; } }``````

Does this make sense to you? And thats what I meant when i said you could put all your couts on one line. This makes it much easier to read, and shaves off about 45 lines of unnecessary code.

EDIT:
Although to be perfectly honest, I'm not sure if endl works multiple times in a single cout. I don't see why it wouldn't but if this isn't the case feel free to correct me.
Last edited on
closed account (3qX21hU5)
Endl does work as many time in a single cout. Endl is the same as \n except it also flushes the buffer.
Ok I tried replacing the switch statement with your suggestion to see if it works but but it dosnt.
I did:

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344`` ``````#include #include #include using namespace std; int dice1, dice2 = 0; void RollDice(); // The Void Program That Rolls The Dice int main() { srand(time(0)); int input = 1; int counter = 1 while(counter <= 2) { switch(dice1) //Switch Statement That Has All The Possible Outcomes For Dice 1 { case 1: cout <<"player "<< counter << endl << endl << "[ . ] " << endl; break; case 2: cout <<"player "<< counter << endl << endl << "[ : ] " << endl; break; case 3: cout <<"player "<< counter << endl << endl << "[. :] " << endl; break; case 4: cout <<"player "<< counter << endl << endl << "[: :] " << endl; break; case 5: cout <<"player "<< counter << endl << endl << "[:.:] " << endl; break; case 6: cout <<"player "<< counter << endl << endl << "[:::] " << endl; break; } }``````
You left out the dice1 = rand()%6+1
Now this compiles continiously. What did i do wrong?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748`` ``````#include #include #include using namespace std; int dice1=0, dice2 = 0; void RollDice(); // The Void Program That Rolls The Dice int main() { srand(time(0)); int input = 1; int dice1; dice1 = (rand()%6+1); int counter = 1; while(counter <= 2) { switch(dice1) //Switch Statement That Has All The Possible Outcomes For Dice 1 { case 1: cout <<"player "<< counter << endl << endl << "[ . ] " << endl; break; case 2: cout <<"player "<< counter << endl << endl << "[ : ] " << endl; break; case 3: cout <<"player "<< counter << endl << endl << "[. :] " << endl; break; case 4: cout <<"player "<< counter << endl << endl << "[: :] " << endl; break; case 5: cout <<"player "<< counter << endl << endl << "[:.:] " << endl; break; case 6: cout <<"player "<< counter << endl << endl << "[:::] " << endl; break; system ("Pause"); return EXIT_SUCCESS; } }} ``````
Topic archived. No new replies allowed.