Can someone help me finish this code off. Its a simple program that prompts two players to pick a card. Each picks between 0-51. An array is holding each of the cards by rank and suit using a struct. Everything works great except the greater_than function. The only issue with it is getting the Ace which is 1, to "beat out" the other cards. The high card as it stands now is the king which is 13. The mix function is commented on purpose so I can find the Ace for testing purposes. It is just that one glitch that is getting me. Please help!!! I'm pretty new to this, so go easy on me. I know its probably a simple fix.
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;
struct card {
int rank;
char suit;
};
void create (card deck [52]);
void mix (card deck [52]);
bool greater_than (card c1, card c2);
void print_card (card& c1);
void print_deck (card deck [52]);
int main(int argc, char *argv[])
{
srand (time(0));
card my_array [52];
int p1;
int p2;
cout << "Player 1: Pick the position of your card in the deck: ";
cin >> p1;
cout << "Player 2: Pick the position of your card in the deck: ";
cin >> p2;
cout << endl;
create (my_array);
// mix (my_array);
cout << "Player 1 Card: ";
print_card (my_array[p1]);
cout << "Player 2 Card: ";
print_card (my_array[p2]);
cout << endl;
greater_than (my_array [p1], my_array [p2]);
print_deck (my_array);
system("PAUSE");
return EXIT_SUCCESS;
}
void create (card deck [52])
{
int r;
char s;
int index;
index = 0;
for (r = 1; r <= 13; r++)
for (s = 3; s <= 6; s++)
{
deck[index].rank = r;
deck[index].suit = s;
index++;
}
}
/*void mix (card deck [52])
{
int i;
int x;
card temp;
for (i = 0;i < (52 - 1);i++)
{
x = i + (rand() % (52 - i));
temp = deck [i];
deck [i] = deck [x]; deck[x] = temp;
}
}*/
bool greater_than (card c1, card c2)
{
if (c1.rank > c2.rank)
return cout << "Player 1 Wins!" << endl << endl;
else
return cout << "Player 2 Wins!" << endl << endl;
}
void print_card (card& c1)
{
if (c1.rank == 1)
{
cout << "Ace" << " of " << c1.suit << endl;
}else if (c1.rank == 11){
cout << "Jack" << " of " << c1.suit << endl;
}else if (c1.rank == 12){
cout << "Queen" << " of " << c1.suit << endl;
}else if (c1.rank == 13){
cout << "King" << " of " << c1.suit << endl;
}else{
cout << c1.rank << " of " << c1.suit << endl;
}
}
void print_deck (card deck [52])
{
int index;
index = 0;
cout << "\nThe Deck is: " << endl;
for (index = 0;index < 52;index++)
print_card (deck[index]);
}