Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- char ans; long sec; int x; int i(0); int satu(0), dua(0);
- int a, b, c, d; int adds(0), addd(0);
- time (&sec);
- srand((unsigned)sec);
- cout<<"Player 1: "<<satu<<endl;
- cout<<"Player 2: "<<dua<<endl;
- cout<<"Press r to random player"<<endl;
- cin>>ans;
- x=rand()%2+1;
- int m=x;
- cout<<"Player "<<x<<" rolls dice first"<<endl;
- for(i=0; i<999; i++)
- {
- cout<<"Press d to roll dice"<<endl;
- cin>>ans;
- a=rand()%6+1;
- b=rand()%6+1;
- c=rand()%6+1;
- d=rand()%6+1;
- if(x==1)
- {
- cout<<"Player 1 dice values: "<< a<<" "<< b<<endl;
- cout<<"Player 2 dice values: "<< c<<" "<< d<<endl;
- adds=a+b;
- addd=c+d;
- if(a==b)
- {adds=0;}
- if (c==d)
- {addd=0;}
- satu+=adds;
- dua+=addd;
- cout<<"Player 1: "<<satu<<endl;
- cout<<"Player 2: "<<dua<<endl;
- }
- else
- {
- cout<<"Player 2 dice values: "<< c<<" "<< d<<endl;
- cout<<"Player 1 dice values: "<< a<<" "<< b<<endl;
- adds=a+b;
- addd=c+d;
- if(a==b)
- {adds=0;}
- if (c==d)
- {addd=0;}
- satu+=adds;
- dua+=addd;
- cout<<"Player 1: "<<satu<<endl;
- cout<<"Player 2: "<<dua<<endl;
- }
- if (satu>=30)
- {
- i=1000;
- m=1;
- }
- if (dua>=30)
- {
- i=1000;
- m=2;
- }
- }
- cout<<"Player "<<m<<" wins"<<endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment