Ok, this is actually very simple I just can't figure it out... first of all I'm a complete beginner in C++ and I was given this assignment to do a dice game (yes assignment, please note that I'm not looking for a code, just help on how to do it). Here's a code for the dices:


srand(time(0));
dice1=rand() % 6 + 1;
dice2=rand() % 6 + 1;
cpudice1=rand() % 6 + 1;
cpudice2=rand() % 6 + 1;

There are 3 rounds then you win or lose, but here the thing: how do I loop this so that I can throw again? Also I need to do so that if someone wins 2 times in a row the 3rd round isn't played at all, I'm stuck, please help me understand loop, I know that there are three, while do-while and for, what should I use and how?

Again I must write that I do not want a complete code how to do this, I want some help understanding what I'm supposed to do, and yes I am aware that this is simple and I will seem like an idiot lol.

Thanks :)

Recommended Answers

All 2 Replies

Make a function that return a random int from 1-6;

then

player1 = randomDiceRoll();
player2 = randomeDiceRoll();
//and so on.

have a counter that counts points.
int playerPoints =0;
int compPoints = 0;

//use a while loop
while(true)
{
//roll dice
//check winner
//add points to winner
//check if game is over
if(playerPoints >= 2 ) { cout<<"Player won\n"; break; }
else if(compPoints >=2) { cout<<"comp won\n"; break; }
}

I would put a while() loop with a bool variable in it

while(!done)

and every time you win a point you add 1 to your score and 1 to the computers score when he wins. When one of the scores reach 2 then just make done = true and the loop will stop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.