Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream.h>
- #include <stdlib.h>
- #include <time.h>
- int main()
- {
- srand(time(NULL));
- int randCard1;
- int randCard2;
- int randCard3;
- int randCard4;
- int randCard5;
- int randCard6;
- double total1;
- double total2;
- char again;
- double you=0;
- double computer=0;
- double draw=0;
- int howmany;
- do{
- cout<<"How many cards do you want(1-5) : "<<endl;
- randCard1=rand()%9+1;
- randCard2=rand()%9+1;
- randCard3=rand()%9+1;
- randCard4=rand()%9+1;
- randCard5=rand()%9+1;
- cin>>howmany;
- if(howmany==1)
- {total1=randCard1;
- cout<<"You: "<<(randCard1)<<endl;}
- else if(howmany==2)
- {total1=randCard1+randCard2;
- cout<<"You: "<<(randCard1)<<" "<<(randCard2)<<endl;}
- else if(howmany==3)
- {total1=randCard1+randCard2+randCard3;
- cout<<"You: "<<(randCard1)<<" "<<(randCard2)<<" "<<(randCard3)<<endl;}
- else if(howmany==4)
- {total1=randCard1+randCard2+randCard3+randCard4;
- cout<<"You: "<<(randCard1)<<" "<<(randCard2)<<" "<<(randCard3)<<" "<<(randCard4)<<endl;}
- else if(howmany==5)
- {total1=randCard1+randCard2+randCard3+randCard4+randCard5;
- cout<<"You: "<<(randCard1)<<" "<<(randCard2)<<" "<<(randCard3)<<" "<<(randCard4)<<" "<<(randCard5)<<endl;}
- cout<<"Computer: "<<(randCard4=rand()%9+1)<<" "<<(randCard5=rand()%9+1)<<" "<<(randCard6=rand()%9+1)<<endl;
- total2=randCard4+randCard5+randCard6;
- cout<<"I have "<<total2<<" and you have "<<total1;
- if((total1>21)&(total2>21))
- {
- cout<<" so we draw."<<endl;
- draw++;
- }
- else if(total1>total2&total1<22)
- {
- cout<<" so you win."<<endl;
- you++;
- }
- else if(total2>21)
- {
- cout<<" so you win."<<endl;
- you++;
- }
- else if(total1<total2)
- {
- cout<<" so I win."<<endl;
- computer++;
- }
- else if(total1>21)
- {
- cout<<" so I win."<<endl;
- you++;
- }
- else if(total1==total2)
- {
- cout<<" so we draw."<<endl;
- draw++;
- }
- cout<<"Would you like to play again? (Y/N) ";
- cin>>again;
- }
- while(again=='y');
- cout<<"Computer wins: "<<computer<<endl;
- cout<<"Your wins: "<<you<<endl;
- cout<<"Draws: "<<draw<<endl;
- cout<<endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment