I am trying to create a card game in C++ that every turn a user will drop a card from their hand or add a card to their hand depending on the input by the user. I need to create a deck of cards and for some reason what I have now is giving me a segmentation fault or floating point exception core dump when I try to print the deck to see if it is working. Any ideas how to fix this? I declared int i before these for loops that is not the error.
Thank you!
C is a card type, card is a class that holds an int rank and a char suit. Availdeck is of Deck type, deck is also a class that holds number of cards and a cards array of 52 cards (the array is also of card class type).
You're calling AddCard() 208 times. You haven't shown the declaration of Deck, but you stated above that it holds 52 cards. You're going to get an out of bounds reference when you try to add the 53rd card.
You have nested loops, but you don't in fact need the outer loop.
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
what should I do if I am getting the same error when I only use the single loop? Thanks so much for your help!
This is how I am trying to test if my deck is being filled, maybe I am printing it out incorrectly?:
what should I do if I am getting the same error when I only use the single loop?
Step through your code in a debugger. This will allow you to see exactly where your code is crashing, and examine the contents of the memory at that point to see why it's crashing.
What debugger should I use? The ones Ive found online all give me the output as my console without any further explanation.. thanks so much for all your help!