mardi 29 mars 2016

Card Shuffling and Dealing program not running

Hi all I have a code that I'm running on Eclipse (MAC OS X) and I was wondering why my code is not running. There are no errors in the code itself (or so I hope) however my compiler tells me the following error:

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [testfile] Error 1

here is my code:

#ifndef H_card
#define H_card
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
using namespace std;

class card {
private:
    string face;
    string suit;
public:
    card(string cardFace, string cardSuit);
    string print() const;
    card();
};

card::card()
{
}

card::card(string cardFace, string cardSuit)
{
    face = cardFace;
    suit = cardSuit;
}

string card::print() const
{
    return (face + "of" + suit);
}
#endif

const int CARDS_PER_DECK = 52;

class deckOfCards
{
public:
    deckOfCards();
    void shuffle();
    card dealCard();
    void printDeck() const;
private:
    card *deck;
    int currentCard;
};
deckOfCards::deckOfCards()
{
    string faces[] = { };
    string suits[] = { };
    deck = new card[CARDS_PER_DECK];
    currentCard = 0;
    for(int count = 0; count < CARDS_PER_DECK; count++)
        deck[count] = card(faces[count % 13], suits[count / 13]);
}

void deckOfCards::shuffle()
{
    for(int first = 0; first < CARDS_PER_DECK; first++)
    {
        int second = (rand() + time(0)) % CARDS_PER_DECK;
        card temp = deck[first];
        deck[first] = deck[second];
        deck[second] = temp;
    }
}

card deckOfCards::dealCard()
{
    if(currentCard > CARDS_PER_DECK)
        shuffle();
    if(currentCard < CARDS_PER_DECK)
        return (deck[currentCard++]);
    return (deck[0]);
}

int main()
{
    deckOfCards deck;
    card currentCard;
    deck.printDeck();
    deck.shuffle();
    cout << endl << endl;
    deck.printDeck();
    deck.shuffle();
    cout << endl << endl;
    for(int i = 0; i < 52; i++)
    {
        currentCard = deck.dealCard();
        cout << currentCard.print() << endl;
    }
    system("PAUSE");
    return 0;
} 

Aucun commentaire:

Enregistrer un commentaire