ok, so i am making a cribbage game, i had it so it printed the first hand, allowed you to discard 1, and again for a second card, then the same for the second hand, followed by then adding the starter card to the vectors, then adding up the score(the scoring isnt complete yet but i cant work on it untill it works), but i had a separate function to print each vector(hands and deck), sort each hand and to discard from each hand, so i altered the functions so you just pass an arguement through, making my code shorter, however the program now just prints the first hand and asks for which one to dicard, but on the print, the sort hasnt worked, and upon discarding, that appears to not work, however when i tested a print of the discarded cards, the ones i discarded appeared, however they were not removed from the hand, so it moves correctly, so either the sort and discard functions do not work, or there is something wrong with printing function, all these functions are in a class, here is my int main:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include "class.cpp"
#include "deck class.cpp"
using namespace std;
vector<Card> deck1;
/** this void function creates a vector of 'card' objects using the push_back
function*/
void createDeck()
{
int n,i,j;
string b;
j = 0;
for(n = 0; n < 4; n++)
{
for(i = 1; i < 14; ++i)
{
switch (n)
{
case 0: b = "Hearts";
break;
case 1: b = "Spades";
break;
case 2: b = "Diamonds";
break;
case 3: b = "Clubs";
break;
};
deck1.push_back(Card(i, b));
}
}
}
int main()
{
cout << "welcome to Andrew's crib game" << endl;
cout << endl;
srand ( time(NULL) );
createDeck();
Deck deckofcards(deck1);
deckofcards.game();
return 0;
}
|