c How would I create a simple dice game with three players t
c++
How would I create a simple dice game with three players that uses 6 dice at once. Each player rolls the 6 dice once each turn and their score is added up and saved to be added to their next turn. This would go on until one player reaches 10,000.
Solution
#include <iostream>
#include <stdlib.h>
using namespace std;
int main() {
// your code goes here
int dice;
int p1 = 0 ,p2 = 0,p3 = 0;
int i = 0;
while(p1<=10000 || p2<=10000 || p3<=10000)
{
i = (i%3) + 1;
cout << \"Player \" << i << \" turn : \";
dice = rand() % 6 + 1;
cout << \"\ Dice value is : \" << dice << endl;
if(i==1)
p1 = p1+dice;
else if(i==2)
p2 = p2+dice;
else
p3 = p3+dice;
}
return 0;
}
