FrostHard

Dice roll game

Oct 30th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. char ans; long sec; int x; int i(0); int satu(0), dua(0);
  10. int a, b, c, d; int adds(0), addd(0);
  11. time (&sec);
  12. srand((unsigned)sec);
  13. cout<<"Player 1: "<<satu<<endl;
  14. cout<<"Player 2: "<<dua<<endl;
  15. cout<<"Press r to random player"<<endl;
  16. cin>>ans;
  17. x=rand()%2+1;
  18. int m=x;
  19. cout<<"Player "<<x<<" rolls dice first"<<endl;
  20.  
  21. for(i=0; i<999; i++)
  22. {
  23. cout<<"Press d to roll dice"<<endl;
  24. cin>>ans;
  25. a=rand()%6+1;
  26. b=rand()%6+1;
  27. c=rand()%6+1;
  28. d=rand()%6+1;
  29. if(x==1)
  30. {
  31. cout<<"Player 1 dice values: "<< a<<" "<< b<<endl;
  32. cout<<"Player 2 dice values: "<< c<<" "<< d<<endl;
  33. adds=a+b;
  34. addd=c+d;
  35. if(a==b)
  36. {adds=0;}
  37. if (c==d)
  38. {addd=0;}
  39. satu+=adds;
  40. dua+=addd;
  41. cout<<"Player 1: "<<satu<<endl;
  42. cout<<"Player 2: "<<dua<<endl;
  43. }
  44. else
  45. {
  46. cout<<"Player 2 dice values: "<< c<<" "<< d<<endl;
  47. cout<<"Player 1 dice values: "<< a<<" "<< b<<endl;
  48. adds=a+b;
  49. addd=c+d;
  50. if(a==b)
  51. {adds=0;}
  52. if (c==d)
  53. {addd=0;}
  54. satu+=adds;
  55. dua+=addd;
  56. cout<<"Player 1: "<<satu<<endl;
  57. cout<<"Player 2: "<<dua<<endl;
  58. }
  59. if (satu>=30)
  60. {
  61. i=1000;
  62. m=1;
  63. }
  64. if (dua>=30)
  65. {
  66. i=1000;
  67. m=2;
  68. }
  69. }
  70. cout<<"Player "<<m<<" wins"<<endl;
  71. return 0;
  72. }
Add Comment
Please, Sign In to add comment