Question: I'm supposed to make a program where it prints out an array of 52 card objects Example: Ace of Spades, Queen of Hearts, etc. This
I'm supposed to make a program where it prints out an array of 52 card objects
Example: "Ace of Spades", "Queen of Hearts", etc.
This is the code I have right now:
Card.h:
#pragma once #include
Card.cpp:
#include
main.cpp:
#include
void shuffle(Card* cards[], int n) { int temp=0; srand(time(NULL)); for (int i = n - 1; i > 0; i--) { int j = rand() % (i + 1); cards[temp] = cards[i]; cards[i] = cards[j]; cards[j] = cards[temp]; } } int main() { Card* cards[52]; int x= 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 13; j++) { cards[x] = new Card(j, i); x++; } } int y = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 13; j++) { cards[y]->print(); y++; } } return 0; }
I believe the code should work fine but no matter what, I just get 52 lines of the same string: "Undefined of Undefined"
Can anyone point the problem to me?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
