1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#include <cstdlib>
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <set>
#include <algorithm>
void getdata(int);
int randomize(int[],int[]);
using namespace std;
int main(int argc, char *argv[])
{const int HIGH=52;//constant for lowest possible card # which is KD.
const int LOW=1;//Constant for lowest possible card # which is AC.
const int cardnumbers[52]={1,2,3,4,5,6,7,8,9,10,11,12,13,//CLUBS
14,15,16,17,18,19,20,21,22,23,24,25,26,//SPADES
27,28,29,30,31,32,33,34,35,36,37,38,39,//HEARTS
40,41,42,43,44,45,46,47,48,49,50,51,52//DIAMONDS
};//array to hold card #'s.
string cardnames[52]={"AC","2C","3C","4C","5C","6C","7C","8C","9C","10C","JC","QC","KC",//CLUBS
"AS","2S","3S","4S","5S","6S","7S","8S","9S","10S","JS","QS","KS",//SPADES
"AH","2H","3H","4H","5H","6H","7H","8H","9H","10H","JH","QH","KH",//HEARTS
"AD","2D","3D","4D","5D","6D","7D","8D","9D","10D","JD","QD","KD"//DIAMONDS
};//array to hold card abbreviations.
int rand_cards[21];//array to hold cards chosen by random number genorator. Populated by a loop and displayed on screen.
int choice,card1=1,i,x,rand_num,card2,shuffle2,new_rand,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.
char shuffle;
string name;
set<int>unique_cards;
set<int>::iterator it;
pair<set<int>::iterator,bool> ret;
cout<<"What is your name? ";
cin>>name;
cout<<"What would you like to do "<<name<<" ?"<<endl;//Give user a choice
cout<<"Press 1 to continue "<<endl;//Allows user to continue with program
cout<<"Press 2 to quit "<<endl;//Allows user to escape from program
cin>>choice;//enter choice, either 1 or 2.
switch(choice)
{
case 1:
{
cout<<"Lets proceed with the card trick then"<<endl;
cout<<"Press the letter 's' to shuffle the cards"<<endl<<endl;
cin>>shuffle;//inputing 's' starts the loop which will generate 21 random numbers coresponding to 21 random cards out of 52 possible cards.
cout<<endl;
for(i=0;i<=22;i++)//loop to generate 1st set of random numbers
{
unique_cards.insert(card1=(rand()+time(NULL))%(HIGH - LOW + 1) + LOW);
for (it=unique_cards.begin(); it!=unique_cards.end(); it++)//loop to
{
for(int r=0;r<21;++r)//loop to store 1st set of random numbers into an array
{
cout<<" "<<*it;//just to make sure PRNG is working
cin>>it;//inputs random numbers into array
rand_cards[r]=it;
cout<<rand_cards[r]<<" ";//cout to make sure that the code is actually storing the rand #'s into array
}//end of 3rd for loop
}//end of 2nd for loop
}//end of 1st for loop
cout<<"Pick a card "<<name<<" , any card but don't tell me which one it is.Press ENTER to continue"<<endl<<endl;
}//end of case 1
break;
case 2:
cout<<"Thanks for playing "<<name<<" ."<<endl<<endl;
break;
}//end of case 1
system("PAUSE");
return EXIT_SUCCESS;
}
|