vector not returning expected value

Good day,

I am trying to use vectors and classes to write a card class an expand my experience with these. My issue is when I try and print out the whole deck i just get a repeating value of -858993460. My expected value would be something like 4H or 12S.

This is my main.cpp
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
58
59
60
61
62
63
64
65
// CardClass.cpp : Defines the entry point for the console application.
//

#include "Card.h";
#include <vector>;

void fillDeck(vector<Card>&);
//fillDeck - build a new deck
//@parm vector<Card>& - cards in deck

void printDeck(vector<Card>&);

int main()
{
	int holder;

	vector <Card> Deck;
	
	fillDeck(Deck);

	printDeck(Deck);
	cin >> holder; 

    return 0;
}

void printDeck(vector<Card>& deck) {
	unsigned int i = deck.size();
	
	for (unsigned int x = 0; x < i; x++) {

	cout << deck[x].getSuit() << deck[x].getValue() << endl;
	}

}

void fillDeck(vector<Card>& newDeck) {
	//the variables we will be using to fill the deck
	char suit;
	int value;
	//Two for loops to run through 13 cards in all four suits
	for (int i = 0; i < 4; i++) {
		for (int x = 0; x < 13; x++) {
			//Define our suits
			switch (i) {
			case 0: suit = 'H';
				break;
			case 1: suit = 'D';
				break;
			case 2: suit = 'S';
				break;
			case 3: suit = 'C';
				break;
			}

			//value of new card
			//x + 1 because x starts at 0
			value = x + 1;
			//cout << suit << value << endl;
			Card newCard (suit, value);
			newDeck.push_back(newCard);
		}
	}
}


This is my Card.cpp
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
#include "Card.h"

Card::Card() {


}

Card::Card(char suit, int value) {

}

Card::~Card() {

}

int Card::getValue() const {
	return value;
}

char Card::getSuit() const {
	return suit;
}

void Card::printCard() const{

	cout << suit, value;

}


This is my Card.h
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
 // header

#ifndef CARD_H
#define CARD_H
#include <iostream>
#include <string>
using namespace std;

class Card {

public:
	//Default Constructor
	Card();

	//Overload Constructor
	Card(char, int);

	//Destructor
	~Card();

	//Accessor Functions
	char getSuit() const;
	//getSuit
	//@return char - suit of the card

	int getValue() const;
	//getValue
	//@return int - value of the card

	void printCard() const;

private:
	//Member Variables
	char suit;
	int value;




};



#endif  


Any help is appreciated!
hang on. hidden / misaligned bracket on end of a statement threw me. I know its a legit style but

a big long line of code with a bracket stuff {

} //misaligned, not in same column as the opener

messes me up at times.
Last edited on
Found it. your card(a,b) contstructor does not do anything. It should use the 2 parameters to assign the fields.
Dang its always something simple I'm just not seeing,

thank you!
Topic archived. No new replies allowed.