Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <sstream>
- #include <string>
- 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,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.
- char shuffle;
- cout<<"What would you like to do? "<<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.
- if(choice==1)
- {
- cout<<"Lets proceed with the card trick then"<<endl;
- cout<<"Press the letter 's' to shuffle the cards"<<endl<<endl;
- cin>>shuffle;//inputing 0 starts the loop which will generate 21 random numbers coresponding to 21 random cards out of 52 possible cards.
- cout<<endl;
- card1=(rand()+time(0))%(HIGH - LOW + 1) + LOW;//randomly generates an integer between 1 and 52. GIves the first random # only.
- card1=rand_cards[0];
- cout<<card1 <<",";//out put the card to the screen
- for(i=1;i<21;i++)//starts array at position 1 (2nd row) and runs through 20 itterations.
- {
- do
- {
- card2=(rand()+time(0))%(HIGH - LOW + 1) + LOW;
- rand_cards[i];
- cout<<card2<<",";
- }
- 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.
- {
- 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.
- {
- rand_cards[i]='/0';
- }//end of if statement
- }//end of while statement
- }//end of for statement
- cout<<endl;
- cout<<"Pick a card, any card but don't tell me which one it is.Press ENTER to continue"<<endl<<endl;
- }//end of if loop
- else
- cout<<"Thanks for playing."<<endl<<endl;
- system("PAUSE");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement