I am working on an assignment that involves creating a simplified poker game. I am new to C++, but this is for class, so I am here to learn. Anyways...
After I deal each players hand vector, how would I sort the vector before it prints? They are char vectors called hand1 for player 1, and hand2 for player 2. The deck vector is a char as well, but the rank array is a string (so that the number 10 prints), and the suit array is a char (so that the actual symbols print). Instead of printing: 8<heart>, 3<club>, A<spade>, 4<spade>, 9 <diamond>, 8<club>, 2<club>, it would print: 2<club>, 3<club>, 4<spade>, 8<heart>, 8<club>, 9 <diamond>, A<spade>.
I hope this was enough information. I can send my code if you'd like to look at it. No pointers, no classes. I'm not at that level yet (unless there is no other way to do what I am asking). I can improve upon this project in my next class.
The problem is if you store everything as chars and strings it prints nicely, but it's not at all clear how it should be sorted. You want to store the rank as an int (or similar integral type) and then it will be easier to sort. If you have a problem printing (like 11 should be J) then just create a custom print function that is passed an int, and prints it's rank value.
This would be way easier if you could use classes. You could abstract what a card is, and what makes one card greater then another, as well as how to print a card to standard output, and then it would be as simple as:
1 2
vector<Card> hand;
sort( hand.begin(), hand.end() ); //(see link below)