C I need to store the scores of three players until the next

C++

I need to store the scores of three players until the next turn in a dice game. Then the new score is added to the previous one and so on until I reach 10,000.

Solution

Code:

#include <iostream> // std::cin, std::cout
#include <fstream> // std::ifstream
#include <map>
#include<cstdlib>
#include<ctime>
using namespace std;
int main () {
   int p1=0;
   int p2=0;
   int p3=0;
   while(p1<10000 &&p2<10000 && p3<10000)
   {
       p1 += (rand() % 6 + 1);//generates no between 1 to 6
       p2 += (rand() % 6 + 1);//generates no between 1 to 6
       p3 += (rand() % 6 + 1);//generates no between 1 to 6
   }
   cout<<p1<<endl;
cout<<p2<<endl;
cout<<p3<<endl;
if(p1>p2 && p1 > p3)
cout<<\"p1 wins\"<<endl;
if(p2>p1 && p2 > p3)
cout<<\"p2 wins\"<<endl;
if(p3>p2 && p3 > p1)
cout<<\"p3 wins\"<<endl;
return 0;
}

C++ I need to store the scores of three players until the next turn in a dice game. Then the new score is added to the previous one and so on until I reach 10,0

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site