Code:
#include <cstdlib>
#include <iostream>
using namespace std;
int add_point(string);
int main(int argc, char *argv[])
{
// This part of the code, builds a array of 199 random numbers
srand ( (unsigned)time ( NULL ) );
int var[200];
for (int i = 0; i < 199; i++ )
var[i] = ( rand() % 100 );
/*This part builds a deck of cards, I had to use a different array for each
suit so that I would deal the same card twice. And I also had to use a
string because if I used a char it wouldn't display "10" because it is 2 characters… I think*/
string getSpade[13] = {"A", "2", "3", "4", "5" ,"6", "7", "8", "9", "10", "J", "Q", "K"};
random_shuffle(getSpade, getSpade + 13);
string getHeart[13] = {"A", "2", "3", "4", "5" ,"6", "7", "8", "9", "10", "J", "Q", "K"};
random_shuffle(getHeart, getHeart + 13);
string getDiamond[13] = {"A", "2", "3", "4", "5" ,"6", "7", "8", "9", "10", "J", "Q", "K"};
random_shuffle(getDiamond, getDiamond + 13);
string getClub[13] = {"A", "2", "3", "4", "5" ,"6", "7", "8", "9", "10", "J", "Q", "K"};
random_shuffle(getClub, getClub + 13);
//These arrays are there to count the number of cards from each suit a player would get.
int nextSpade = 0, nextHeart = 0, nextDiamond = 0, nextClub = 0;
int f = 0, i = 0, spp1 = 0, hep1 = 0, dip1 = 0, clp1 = 0;
/*This loop was the most random way I could get the program to deal cards.
First it check the value of "var[f]" to see if it is odd or even. if that true
Then it checks to see if all the spades have been dealt, if they haven't it then
check to see if that player hasn't all ready received 13. (this program is a bridge
card dealer, 13 cards per player 4 players) then finally if all the values are met,
it adds one to nextSpade or nextHeat etc etc*/
do
{
if ((var[f]%2 != 0) && (nextSpade <= 12) && (i <= 12))
{ nextSpade++; i++; spp1++; } f++;
if ((var[f]%2 != 0) && (nextHeart <= 12)&& (i <= 12))
{ nextHeart++; i++; hep1++; } f++;
if ((var[f]%2 != 0) && (nextDiamond <= 12)&& (i <= 12))
{ nextDiamond++; i++; dip1++; } f++;
if ((var[f]%2 != 0) && (nextClub <= 12)&& (i <= 12))
{ nextClub++; i++; clp1++; } f++;
} while (i <= 12);
/*This section of code is the display part, it prints the first card,
then increases i, display the next card etc etc and will loop until
i = the number of cards that player is meant to get for that suit*/
cout << "Player One \n"
<< "S: ";
for (int i = 0; i <= nextSpade-1; i++)
cout << getSpade[i] << " ";
cout << endl;
cout << "H: ";
for (int i = 0; i <= nextHeart-1; i++)
cout << getHeart[i] << " ";
cout << endl;
cout << "D: ";
for (int i = 0; i <= nextDiamond-1; i++)
cout << getDiamond[i] << " ";
cout << endl;
cout << "C: ";
for (int i = 0; i <= nextClub-1; i++)
cout << getClub[i] << " ";
cout << endl;
i=0; int spp2 = spp1, hep2 = hep1, dip2 = dip1, clp2 = clp1;
// same a previous loop for player one
do
{
if ((var[f]%2 != 0) && (nextSpade <= 12) && (i <= 12))
{ nextSpade++; i++; spp2++; }
f++;
if ((var[f]%2 != 0) && (nextHeart <= 12) && (i <= 12))
{ nextHeart++; i++; hep2++; }
f++;
if ((var[f]%2 != 0) && (nextDiamond <= 12) && (i <= 12))
{ nextDiamond++; i++; dip2++; }
f++;
if ((var[f]%2 != 0) && (nextClub <= 12) && (i <= 12))
{ nextClub++; i++; clp2++; }
f++;
} while (i <= 12);
// just the same as loop from player one, but this one i = spp1, which is the number
// of cards of that suit that the previous player was dealt...
cout << "Player Two \n"
<< "S: ";
for (int i = spp1; i <= nextSpade-1; i++)
cout << getSpade[i] << " ";
cout << endl;
cout << "H: ";
for (int i = hep1; i <= nextHeart-1; i++)
cout << getHeart[i] << " ";
cout << endl;
cout << "D: ";
for (int i = dip1; i <= nextDiamond-1; i++)
cout << getDiamond[i] << " ";
cout << endl;
cout << "C: ";
for (int i = clp1; i <= nextClub-1; i++)
cout << getClub[i] << " ";
cout << endl;
system("pause");
return EXIT_SUCCESS;
}