Guest User

Untitled

a guest
Jul 16th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include <iostream.h>
  2.  
  3. #include <stdlib.h>
  4.  
  5. #include <time.h>
  6.  
  7. int main()
  8.  
  9. {
  10.  
  11. srand(time(NULL));
  12.  
  13. int randCard1;
  14.  
  15. int randCard2;
  16.  
  17. int randCard3;
  18.  
  19. int randCard4;
  20.  
  21. int randCard5;
  22.  
  23. int randCard6;
  24.  
  25. double total1;
  26.  
  27. double total2;
  28.  
  29. char again;
  30.  
  31. double you=0;
  32.  
  33. double computer=0;
  34.  
  35. double draw=0;
  36.  
  37. int howmany;
  38.  
  39. do{
  40.  
  41. cout<<"How many cards do you want(1-5) : "<<endl;
  42.  
  43. randCard1=rand()%9+1;
  44.  
  45. randCard2=rand()%9+1;
  46.  
  47. randCard3=rand()%9+1;
  48.  
  49. randCard4=rand()%9+1;
  50.  
  51. randCard5=rand()%9+1;
  52.  
  53. cin>>howmany;
  54.  
  55. if(howmany==1)
  56. {total1=randCard1;
  57. cout<<"You: "<<(randCard1)<<endl;}
  58.  
  59. else if(howmany==2)
  60. {total1=randCard1+randCard2;
  61. cout<<"You: "<<(randCard1)<<" "<<(randCard2)<<endl;}
  62.  
  63. else if(howmany==3)
  64. {total1=randCard1+randCard2+randCard3;
  65. cout<<"You: "<<(randCard1)<<" "<<(randCard2)<<" "<<(randCard3)<<endl;}
  66.  
  67. else if(howmany==4)
  68. {total1=randCard1+randCard2+randCard3+randCard4;
  69. cout<<"You: "<<(randCard1)<<" "<<(randCard2)<<" "<<(randCard3)<<" "<<(randCard4)<<endl;}
  70.  
  71. else if(howmany==5)
  72. {total1=randCard1+randCard2+randCard3+randCard4+randCard5;
  73. cout<<"You: "<<(randCard1)<<" "<<(randCard2)<<" "<<(randCard3)<<" "<<(randCard4)<<" "<<(randCard5)<<endl;}
  74.  
  75.  
  76. cout<<"Computer: "<<(randCard4=rand()%9+1)<<" "<<(randCard5=rand()%9+1)<<" "<<(randCard6=rand()%9+1)<<endl;
  77.  
  78. total2=randCard4+randCard5+randCard6;
  79.  
  80. cout<<"I have "<<total2<<" and you have "<<total1;
  81.  
  82. if((total1>21)&(total2>21))
  83. {
  84. cout<<" so we draw."<<endl;
  85. draw++;
  86. }
  87.  
  88. else if(total1>total2&total1<22)
  89. {
  90. cout<<" so you win."<<endl;
  91. you++;
  92. }
  93.  
  94. else if(total2>21)
  95. {
  96. cout<<" so you win."<<endl;
  97. you++;
  98. }
  99.  
  100. else if(total1<total2)
  101. {
  102. cout<<" so I win."<<endl;
  103. computer++;
  104. }
  105.  
  106. else if(total1>21)
  107. {
  108. cout<<" so I win."<<endl;
  109. you++;
  110. }
  111.  
  112. else if(total1==total2)
  113. {
  114. cout<<" so we draw."<<endl;
  115. draw++;
  116. }
  117.  
  118. cout<<"Would you like to play again? (Y/N) ";
  119. cin>>again;
  120.  
  121.  
  122. }
  123. while(again=='y');
  124. cout<<"Computer wins: "<<computer<<endl;
  125. cout<<"Your wins: "<<you<<endl;
  126. cout<<"Draws: "<<draw<<endl;
  127.  
  128. cout<<endl;
  129.  
  130.  
  131.  
  132. return 0;
  133. }
Add Comment
Please, Sign In to add comment