Im new to C++ and fairly new to programming in general. I figured a good exercise for me to become familiar with C++'s functionality and syntax would be to create a simple program with a few features based off poker. My first exercise is usually to parse my poker hands.
I know my code is very noobish. I know there are MUCH better ways to create a deck of cards rather than a huge array. However please ignore that. :P
PROBLEM 1
Can you please help me print my array to the console? At the moment it gives me a number. I dont understand where the error in logic is happening. Im assuming it is in my loop.
PROBLEM 2
My idea was to have the array shuffle itself and then deal 2 cards to 9 players, dealing a card to each player before the second round of dealing. I dont know how to get C++ to assign array contents to another variable.
In PERL, I would use the push command to do this. Can you please point out the function or the name of this term in programing so I can look it up myself?
CODE:
/*How many times can you be dealt cards before getting pocket aces
52 cards 9 seats
seat 1 is to left of dealer
shuffle cards array,
*/
if (i == 1) blah = "A";
if (i < 10) blah = i;
if (i == 10) blah = "10";
if (i == 11) blah = "J";
if (i == 12) blah = "Q";
if (i==13) blah = "K";
blah += " " +suit;
deck.push_back (blah);
}
}
cout << "\nPlease select what seat you would like to sit in."
<< "\n(Correct inputs include a single digit numbers 1 through 9)"
<< endl;
cin >> pselection;
if (pselection > 9) {
cout << "\nYou have entered an incorrect input."
<< "\nPlease select what seat you would like to sit in."
<< "\n(Correct inputs include a single digit numbers 1 through 9)"
<< endl;
cin >> pselection;
}
else {
cout >> "One moment please while we shuffle the deck.";
}
You can't assign two char to a char variable. Each element of the array = 1 char variable.
Also, if it's a card game, there is always a set number of cards. Why is a vector needed. I would just make a small struct that defined its value and card type and then make an array of that which should be predefined. A vector shouldn't be needed.
Vector is always the better choice. "Shouldn't be needed?" Sigh. Arrays are prone to all sorts of errors that vectors just aren't. Arrays are low-level junk that C++ programmers no longer have to deal with unless they are doing low-level programming. And that stuff just sucks.
I noticed that char would not work but the fact that it compiled was strange. What is a better option to use in that case? Declaring it as a string and int does not work.
Yeah it's pretty prone to mistake if the array needs to move. But it doesn't...At all...It's a constant 52 at all times....
I would still go with my struct idea whether or not you choose vector or array.
Characters are represented by single quotes. I noticed PanGalactic noted that above incorrectly.
I revised, and then revised again. I meant to say noted....Not that it's incorrect but since he was using a char variable he was supposed to use single quotes. :/