Simulate playing card program

Source: Internet
Author: User

[Cpp]
# Include <stdio. h>
# Include <string. h>
# Include <stdlib. h>
# Include <time. h>
 
 
Struct CARD
{
Char suit [10]; // color
Char face [10]; // card surface
};
 
 
Void Deal (struct CARD * wCard );
Void Shuffle (struct CARD * wCard );
Void FillCard (struct CARD wCard [], char * wFace [], char * wSuit []);
 
 
 
 
Int main ()
{
Char * suit [] = {"Spades", "Hearts", "Clubs", "Diamonds"}; // black and red plum blossom slices
Char * face [] = {"A", "2", "3", "4", "5", "6", "7", "8 ", "9", "10", "Jack", "Queen", "King "};
// Int I;
Struct CARD [52];

Srand (time (NULL ));
FillCard (card, face, suit );
Shuffle (card );
Deal (card );
}
 
 
// Shuffling Process
Void FillCard (struct CARD wCard [], char * wFace [], char * wSuit [])
{
Int I;
 
 
For (I = 0; I <52; I ++)
{
Strcpy (wCard [I]. suit, wSuit [I/13]);
Strcpy (wCard [I]. face, wFace [I % 13]);
}
}
 
 
// Licensing process
Void Shuffle (struct CARD * wCard)
{
Int I, j;
Struct CARD temp;
 
 
For (I = 0; I <52; I ++)
{
J = rand () % 52;
Temp = wCard [I];
WCard [I] = wCard [j];
WCard [j] = temp;
}
}
 
 
// Output the licensing result
Void Deal (struct CARD * wCard)
{
Int I;

For (I = 0; I <52; I ++)
{
Printf ("% 2d: % 10 s % 10s \ n", I + 1, wCard [I]. suit, wCard [I]. face );
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.