Random number generator with rolling a dice

I have to general random number with rolling a dice (6 sides) for 4 players.

[code]
while (maxScore<100)
{
for (p=0; p<player_num; p++)
{
dieVal=rand()%dice+1;
cout<<"Die Value is : "<<dieVal<<" ";
score[p]=+dieVal;
cout<<"Player "<<p+1<<" at the cell of "<<score[p]<<endl;
}

maxScore=0;
if (maxScore<score[p])
maxScore=score[p];
cout<<"Player "<<p+1<<" has the maximum score of "<<maxScore<<endl;
}
cout<<"Player "<<p+1<<" reached the maximum score of "<<n*n<<endl;

** It only generates random number with one time. I need to general random number and sum up the number to see any of 4 player gets 100 first. Please help.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
bool quit = false;
while (!quit)
{
for (p=0; p<player_num; p++)
{
dieVal = rand()%dice+1;
cout<<"Die Value is : "<< dieVal << endl;
score[p] += dieVal;

cout<< "Player "<< p+1 <<" at the cell of "<< score[p] << endl;

if (score[p] >= 100) {quit = true; break;}
}
}

for(int i = 0; i < player_num; i++)
if (score[i] >= 100)
cout<< "Player "<< i+1 << " reached the maximum score of " << score[i] << endl;
Last edited on
For your information :
score[p] =+ dieVal;

This causes a compiler error. Change it to :

score[p] += dieVal;
Does that help you? :)
Sorry. Not working.

So here is the thing.

there are 4 players.
1st player
roll a die
get the score
move to the 2nd player
roll a die
get the score
upto 4th player

every time the score is added up with each die number
until anyone reaches at the score of 100 and more.
My solution updated. Can you please let us know your program output please?
Die Value is : 6
Player 1 at the cell of 1958809960
Player 1 reached the maximum score of 1958809960
Player 2 reached the maximum score of 4247373
Player 3 reached the maximum score of 4249184

--------------------------------
Process exited after 0.01979 seconds with return value 0
Press any key to continue . . .
You didn't initialize your number array from the start.

Put it before the while loop :
for(int i = 0; i < player_num; i++) score[i] = 0;
Topic archived. No new replies allowed.