Arrays need to be initialized with constant values (people's value is not known at compile time, since any value can be passed in, you just can't change that value during the scope of the function).
Use dynamic memory, or a vector:
thanks, I actually haven't learned vectors in school yet, however this is a personal project so time to learn. I will give those a shot and report back in a day or so if I still have problems.
Vectors are a container class that allow you to store a variable amount of data, while handling all of the cleaning up of memory "behind the scene". You should definitely learn to be proficient with them: http://www.cplusplus.com/reference/stl/vector/
They are generally a much better option than allocating dynamic memory yourself.
hmm maybe i should reconsider how I am doing this project. I actually realized that it may be easier to make an array of 52 strings for this game instead of using a 2d array or that mimic 2d array thing you just showed me might work as well. Any thoughts?
What would be the best way to store 52 cards with suits and not lose the suits for each card when shuffling? Otherwise I would end up with like 2 jack of hearts or something potentially i believe.
Why don't you represent cards using a struct, and the suit with an enum? How much C++ do you know? Have you done the tutorials on this site?
1 2 3 4 5 6 7 8 9 10 11 12 13
enum Suit{heart, diamond, club, spade};
struct Card
{
Suit suit;
int value;
};
//Then you can just hold an array/vector of 52 cards, and implement some sort of function to shuffle them around:
int main()
{
Card deck[52];
initialize(deck); //Set the card values properly
shuffle(deck); //Shuffle the cards. You can just swap two cards at random locations a few times.
}
Honestly, all I have done is my intro to programming c++ class in school. I have looked at a few tutorials on this site but not many. I guess I should? I am honestly just trying to make a project to learn new things and progress in c++.
Basically I am a noobie trying to find his way and at a loss of where to go/do to progress... haha.
Thank you for all of the advice so far. My problem with using a struct is how do you make sure that you dont get duplicate suits on the same card.. Aka 2 King of hearts or something.
Guess I have a lot to learn haha. Thank you again for the help. I will try and learn exactly what it is that you did there. I know its a 1d array, but how are you assigning deck 2 different values at the same position?
Like i said im new, so correct me if im wrong, but wouldn't that assign on first run deck[0] to (suit)i and to w? So wouldn't deck[13*i+w-1] be = w? not (suit)i and w?