The error seems to be related to pointers but I can't quite pinpoint what is going on. I'll split the card array into type and suit later but for now I'd like to figure out what is going on with the error, I tried making the parameters of swap pointers with no real success. I'd greatly appreciate any help.
//in functions.cpp
#include "Header.h"
void randomizer()
{
srand(time(NULL));
}
void swap(string a, string b)
{
string temp = a;
a = b;
b = temp;
}
string Card::generateRandomCard()
{
randomizer();
int random = rand() % 52;
cout << "Your draw is: " << card[random] << endl;
return card[random];
}
void Deck::randomize(string arr[], int size)
{
randomizer();
for (int i = size - 1; i > 0; i--)
{
int j = rand() % (i + 1);
swap(arr[i], arr[j]);
}
}
void Deck::printDeck()
{
randomizer();
Card card1;
cards[52] = card1.card[52];
randomize(cards, 52);
for (int i = 0; i < 52; i++)
{
cout << cards[i] << endl;
}
cout << "\nYour hand: " << cards[51] << endl << cards[50] << endl << cards[49] << endl << cards[48] << endl << cards[47] << endl;
cout << "The next card in the deck is: " << cards[48] << endl;
}
//in Header.h
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using namespace std;
void randomizer();
void swap(string a, string b);
class Card
{
public:
string generateRandomCard();
const string card[52] = { "2 of Clubs", "3 of Clubs", "4 of Clubs", "5 of Clubs", "6 of Clubs", "7 of Clubs", "8 of Clubs", "9 of Clubs", "10 of Clubs", "J of Clubs", "Q of Clubs", "K of Clubs", "A of Clubs",
"2 of Spades", "3 of Spades", "4 of Spades", "5 of Spades", "6 of Spades", "7 of Spades", "8 of Spades", "9 of Spades", "10 of Spades", "J of Spades", "Q of Spades", "K of Spades", "A of Spades",
"2 of Hearts", "3 of Hearts", "4 of Hearts", "5 of Hearts", "6 of Hearts", "7 of Hearts", "8 of Hearts", "9 of Hearts", "10 of Hearts", "J of Hearts", "Q of Hearts", "K of Hearts", "A of Hearts",
"2 of Diamonds", "3 of Diamonds", "4 of Diamonds", "5 of Diamonds", "6 of Diamonds", "7 of Diamonds", "8 of Diamonds", "9 of Diamonds", "10 of Diamonds", "J of Diamonds", "Q of Diamonds", "K of Diamonds", "A of Diamonds" };
private:
};
class Deck
{
public:
void randomize(string arr[], int size);
void printDeck();
private:
string cards[52];
};
//in main.cpp
#include "Header.h"
void main()
{
Card card1;
Deck mainDeck;
mainDeck.printDeck();
card1.generateRandomCard();
}