I was given an assignment to simulate a deck of 52 playing cards. I am required to shuffle the deck and all of this must be done using information learned previously in the class thus far. We have made it to arrays, not pointers, and all the basics up to that point. I was able to create the deck of cards using arrays and shuffle them. The next part of the assignment was to determine the location, card number, of the Ace of Hearts. This means that after the deck is shuffled what element of the array is the Ace of hearts located in and report that card number. This is the part I am having trouble with. Here is my code thus far.
Code:
#include <stdio.h>
#include <time.h>
#include <Stdlib.h>
void shuffle (int deck[], int array_size);
int Ace_Hearts (int deck, int value[], int suit[]);
int Queen_Clubs(int deck, int array_size);
int main (void)
{
int deck[52];
int i;
int card;
char suit[4][9]={"Diamonds","Hearts","Clubs","Spades"};
char value[13][7]={"Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King","Ace"};
srand(time(NULL));
for (i=0; i<52; i++)
deck[i]=i;
for(i=0; i<52;i++)
printf( "%s of %s\n" , value[deck[i] % 13] , suit[deck[i] / 13] ) ;
shuffle(deck,52);
printf("\n\n\n");
for(i=0; i<52;i++)
{
printf( "%s of %s\n" , value[deck[i] % 13] , suit[deck[i] / 13] ) ;
}
}
void shuffle(int deck[], int array_size)
{
int i , j , temp ;
for( i = 0 ; i < array_size ; i ++ )
{
j = rand() % array_size ;
temp = deck[i] ;
deck[i] = deck[j] ;
deck[j] = temp ;
}
}
int Ace_Hearts (int deck, int value[], int suit[])
{
int i=0;
}
I am supposed to create a new function to find the Ace of Hearts. I do not know how to look at all the scrambled deck and determine to stop at the Ace of Hearts. I feel like a for loop is needed. Thanks for any help possible.