Guest User

Untitled

a guest
Feb 24th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. while (true)
  8. {
  9. int tn,x,y,z;
  10. cout<<"enter the starting num: "<<endl;
  11. cin>>tn;
  12. x=0;
  13. y=0;
  14. while (true)
  15. {
  16. while (true)
  17. {
  18. if (tn>1);
  19. //cout<<"total : "<<tn<<endl;
  20. break;
  21. }
  22. while (tn<=1)
  23. {
  24. if (tn<=1)
  25. {
  26. cout<<"Error .. please choose a valid number "<<endl;
  27. cin>>tn;
  28. }
  29. }
  30. cout<<"total : "<<tn<<endl;
  31. break;
  32. }
  33. while (true)
  34. {
  35. cout<<"player 1 choose your num. "<<endl; //player 1's turn
  36. cin>>x;
  37. while( x<0 || x==0 || (tn-x)<0 || (x>(2*y) & (y!=0 || x==tn)) )
  38. {
  39. if( x<0 || x==0 || (tn-x)<0 || (x>(2*y) & (y!=0 || x==tn)) )
  40. {
  41. cout<<"err: player 1 choose your num. "<<endl;
  42. cin>>x;
  43. }
  44. else
  45. break;
  46. }
  47. tn-=x;
  48. cout<<"total : " <<tn<<endl;
  49. if (tn==0)
  50. {
  51. cout<<"winner: player 1"<<endl;
  52. break;
  53. }
  54.  
  55. cout<<"player 2 choose your num. "<<endl; //player 2's turn
  56. cin>>y;
  57. while (y<0 || y==0 || (tn-y)<0 || y>(2*x))
  58. {
  59. if (y<0 || y==0 || (tn-y)<0 || y>(2*x))
  60. {
  61. cout<<"err: player 2 choose your num. "<<endl;
  62. cin>>y;
  63. }
  64. else
  65. break;
  66. }
  67. tn-=y;
  68. cout<<"total : " <<tn<<endl;
  69.  
  70. if (tn==0)
  71. {
  72. cout<<"winner: player 2"<<endl;
  73. break;
  74. }
  75. }
  76. cout<<"wanna play again?"<<endl;
  77. cout<<"0-Yes"<<endl;
  78. cout<<"1-May be later"<<endl;
  79. cin>>z;
  80. if (z==1)
  81. {
  82. cout<<"see you later !!"<<endl;
  83. break;
  84. }
  85. }
  86. }
Add Comment
Please, Sign In to add comment