Advertisement
emaansahmed

Assignment #3 Part 2

Apr 26th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.55 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include <sstream>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10. int main(int argc, char *argv[])
  11. { const int HIGH=52;//constant for lowest possible card # which is KD.
  12.  const int LOW=1;//Constant for lowest possible card # which is AC.
  13.  
  14.  const int cardnumbers[52]={1,2,3,4,5,6,7,8,9,10,11,12,13,//CLUBS
  15.                             14,15,16,17,18,19,20,21,22,23,24,25,26,//SPADES
  16.                             27,28,29,30,31,32,33,34,35,36,37,38,39,//HEARTS
  17.                             40,41,42,43,44,45,46,47,48,49,50,51,52//DIAMONDS
  18.                             };//array to hold card #'s.
  19.                            
  20.   string cardnames[52]={"AC","2C","3C","4C","5C","6C","7C","8C","9C","10C","JC","QC","KC",//CLUBS
  21.                         "AS","2S","3S","4S","5S","6S","7S","8S","9S","10S","JS","QS","KS",//SPADES
  22.                         "AH","2H","3H","4H","5H","6H","7H","8H","9H","10H","JH","QH","KH",//HEARTS
  23.                         "AD","2D","3D","4D","5D","6D","7D","8D","9D","10D","JD","QD","KD"//DIAMONDS
  24.                         };//array to hold card abbreviations.
  25.                        
  26.   int rand_cards[21];//array to hold cards  chosen by random number genorator. Populated by a loop and displayed on screen.                      
  27.                          
  28.                          
  29. int choice,card1=1,i,card2,shuffle2,collumn1,collumn2;//shuffle is the integer 0 which initiates a while loop which will go through 21 itterations, therefore, generating 21 random numbers while also eliminating the numbers chosen from the ones remaining.
  30. char shuffle;
  31.    
  32. cout<<"What would you like to do?  "<<endl;//Give user a choice
  33. cout<<"Press 1 to continue "<<endl;//Allows user to continue with program
  34. cout<<"Press 2 to quit "<<endl;//Allows user to escape from program
  35. cin>>choice;//enter choice, either 1 or 2.
  36.  
  37.  
  38. if(choice==1)
  39.  {
  40.   cout<<"Lets proceed with the card trick then"<<endl;
  41.   cout<<"Press the letter 's' to shuffle the cards"<<endl<<endl;
  42.   cin>>shuffle;//inputing 0 starts the loop which will generate 21 random numbers coresponding to 21 random cards out of 52 possible cards.
  43.   cout<<endl;
  44.  
  45.        
  46.          card1=(rand()+time(0))%(HIGH - LOW + 1) + LOW;//randomly generates an integer between 1 and 52. GIves the first random # only.
  47.          card1=rand_cards[0];
  48.          cout<<card1 <<",";//out put the card to the screen
  49.          
  50.          for(i=1;i<21;i++)//starts array at position 1 (2nd row) and runs through 20 itterations.
  51.          {
  52.            do
  53.            {
  54.              card2=(rand()+time(0))%(HIGH - LOW + 1) + LOW;
  55.              rand_cards[i];
  56.              cout<<card2<<",";
  57.            }
  58.            while (card2 != rand_cards[i]);// && i<21);//Checks to see if the newest randomly generated card has been generated before. Displays it on screen an places in aray if it is unique.
  59.            {
  60.               if (card2==rand_cards[i])//If the program finds that the new randomly generated # is the same as one previously generated, then it skips that value and goes through the loop again until a unique value is found.
  61.                  {
  62.                     rand_cards[i]='/0';
  63.                  }//end of if statement
  64.                }//end of while statement  
  65.              }//end of for statement  
  66.       cout<<endl;
  67.       cout<<"Pick a card, any card but don't tell me which one it is.Press ENTER to continue"<<endl<<endl;
  68.  }//end of if loop
  69. else
  70.     cout<<"Thanks for playing."<<endl<<endl;
  71.  
  72.  
  73.  
  74.  
  75.  
  76.     system("PAUSE");
  77.     return EXIT_SUCCESS;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement