Guest User

Heads or Tails

a guest
Jan 17th, 2016
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     srand(time(0));
  9.    
  10.     int run = 1;
  11.     int HT = 0;
  12.     int rolls = 0;
  13.     int rows = 0;
  14.     int Roll1=0; int Roll2=0;
  15.    
  16.     string input = "" ;
  17.    
  18. do {
  19. while (true){ ;
  20.         cout<<"heads or tails?"<<endl<<endl<<"type 1 for heads, or 2 for tails:"<<endl;
  21.     cin>>HT;
  22.     if (HT==1||HT==2)
  23.     break ;
  24.     cout<<endl<<"only 1s and 2s you silly goose"<<endl<<endl<<"try again:"<<endl<<endl;
  25. }
  26.     if (HT==1){cout<<endl<<"you chose Heads"<<endl<<endl;}
  27.     if (HT==2){cout<<endl<<"you chose Tails"<<endl<<endl;}
  28.  
  29.       while (true){ ;
  30.         cout<<"enter number of flips:";
  31.         cin>>rolls;
  32.         if (rolls<=1000000)
  33.         break ;
  34.         cout<<"please enter valid number under or equal to 1000000:"<<endl;
  35.     }
  36.     cout<<endl<<rolls<<" Total flips"<<endl<<endl<<"good luck"<<endl<<endl;
  37.    
  38.    
  39.     while (rolls>0) {
  40.         int Ranroll = 1+(rand()&1);
  41.         if (Ranroll == 1){Roll1++;}
  42.         if (Ranroll == 2){Roll2++;}
  43.         cout<<Ranroll; rows++;
  44.         if (rows>=80){cout<<endl;rows=0;}
  45.         rolls--;
  46.     }
  47.    
  48.     cout<<endl;
  49.         if (Roll1>Roll2&&HT==1){cout<<endl<<"YOU WIN"<<endl<<endl;}
  50.         if (Roll2>Roll1&&HT==2){cout<<endl<<"YOU WIN"<<endl<<endl;}
  51.         if (Roll1>Roll2&&HT==2){cout<<endl<<"you lose"<<endl<<endl;}
  52.         if (Roll2>Roll1&&HT==1){cout<<endl<<"you lose"<<endl<<endl;}
  53.         cout<<"Heads="<<Roll1<<" Tails="<<Roll2<<endl<<endl<<"Sum= "<<Roll1+Roll2<<endl<<endl<<"Try again?"<<endl<<endl;
  54.         HT=0; Roll1=0;Roll2=0;rolls=0;
  55. }while(run=1);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment