dice game

Hi, I’m creating a game where the user challenges the computer in a dice game. I was wondering what the algorithm is for coding a game where the user plays against the computer? Each player, the user and computer get to throw two dices each round. The person with the highest dice score wins the round. The person that wins the most out of 3 rounds wins the game however if someone wins the 2 first rounds, a third one isn’t needed to be played.
You'll need to be able to generate random numbers, either through rand or the <random> library.

It wont really be an "algorithm". All that will happen is that the user will prompt the dice roll (not needed but it wont be fun to watch the game happen without you!) and the random number algorithm will make a random number between 1 and 6 - then repeat once. Then, you'll use the same algorithm to generate two more random numbers that will be the "computer's dice roll".

Just keep track of how many times each user wins:

1
2
3
4
5
6
7
8
9
10
11
int userwin = 0;
int compwin = 0;
if(win()) //win would be a function to see who won
{
     userwin++; //If the function returns 1, then the user won
}

else
{
     compwin++; //If the function returns 0, then the computer won.
}
Topic archived. No new replies allowed.