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
|
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
using std::cout; using std::endl;
using std::cin;
int deck();
int getcard();
int deck() //sets up the deck and shuffles it
{
int deck[52]={2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,11,11,11,11};
int i,p,temp;
srand(time(NULL)); // seed for random function
for (p=0; p<520; p++){
int k = rand()%52;
int l = rand()%52;
temp=deck[k];
deck[k]=deck[l];
deck[l]=temp;
return(deck[i]);
}
}
int getCardCalled=-1; //deal function, incriments every time a card is drawn
int getcard() {
++getCardCalled;
deck();
return(deck[getCardCalled]);
}
int main() //main is for testing to see if the two functions work together
{
cout<<endl;cout<<endl;
int i;
for (i=0; i<52; i++){ //to print out shuffled deck
cout<<deck()<<" ";
}
cout<<endl;cout<<endl;
cout<<getcard(); //to see if it increments correctly
cout<<endl;
cout<<getcard();
cout<<endl;
cout<<getcard();
cout<<endl;
cout<<getcard();
cout<<endl;cout<<endl;
cout<<" Blackjack"<<endl;
cout<<endl;cout<<endl;
}
|