Hi, plz find my small solution.
#include <iostream>
#include <ctime>
#include <string>
using namespace std;
class cPlayer
{
public:
string Pl_name;
int pos;
int pts;
};
cPlayer p1, p2;
int random(int nMin, int nMax)
{ return rand() % (nMax - nMin + 1) + nMin; }
int main()
{
srand(static_cast<unsigned int>(time(NULL)));
p1.pos = 0 ; p1.pts = 0 ;
p2.pos = 0 ; p2.pts = 0 ;
bool flag=false;
int i = 0 ;
char x;
while(true)
{
i = random(1,6);
if(!flag)
{
cout<<"Enter P1 Name ";
cin>>p1.Pl_name;
}
cout << p1.Pl_name<<" is on the square " << p1.pos <<"\n Press Die";
cin>>x ;
cout << " rolled: " << i << std::endl;
while(i > 0)
{
p1.pos++;
if(p1.pos == 36)
{
p1.pos = 0;
p1.pts++;
if(p1.pts == 5) break;
}
i--;
}
cout << p1.Pl_name<< " came to square " << p1.pos << " (" << p1.pts << " token)" << std::endl;
if(p1.pts == 5) break;
i = random(1,6);
if(!flag)
{
cout<<"Enter P2 Name ";
cin>>p2.Pl_name;
flag=true;
}
std::cout << p2.Pl_name<<" is on the square " << p2.pos ;
cout<<"Press Die ";
cin>>x;
cout << " rolled: " << i << std::endl;
while(i > 0)
{
p2.pos++;
if(p2.pos == 36)
{
p2.pos = 0;
p2.pts++;
if(p2.pts == 5) break;
}
i--;
}
std::cout << p2.Pl_name<<" came to square " << p2.pos << " (" << p2.pts << " token)" << std::endl;
if(p2.pts == 5) break;
}
if(p1.pts == 5) std::cout << "The winner is " << p1.Pl_name<< std::endl;
if(p2.pts == 5) std::cout << "The winner is "<< p2.Pl_name << std::endl;
system("PAUSE");
return 0;
}
I feel the output format is junk, plz change it as u like :idea: