Need Help still getting errors

I get an Error on my main program on line 2 saying stack and deck was not declared. Also code for all three files below with output. I have tried many things but just keep getting more errors so i took it to the interwebs before it all jacked up
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
CARD CLASS
include <iostream>
#include <clocale>
using namespace std;

const wchar_t heart[] = L"\u2665";
const wchar_t diamond[] = L"\u2666";
const wchar_t club[] = L"\u2663";
const wchar_t spade[] = L"\u2660";
setlocalejavascript:tx('code')(LC_ALL, "");

class card
{
private:
   char suit;
   int rank;
public:
   void create(char s, int r)
   {
   suit = s;
   rank = r;
   }

   void print()
   {
   string denom = NULL;
   if(rank == 1) denom = "Ace";
   else if(rank == 11) denom = "Jack";
   else if(rank == 12) denom = "Queen";
   else if(rank == 13) denom = "King";

   if(suit == 'h')
   {
       cout<< denom << " of ";
       wcout << heart << L'\n';
   }
   if(suit == 'd')
   {
       cout<< denom << " of ";
       wcout << diamond << L'\n';
   }
   if(suit == 'c')
   {
       cout<< denom << " of ";
       wcout << club << L'\n';
   }
   if(suit == 's')
   {
       cout<< denom << " of ";
       wcout << spade << L'\n';
   }
}


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
66
67
68
69
70
71
72
73
74
75
76
< // STACK CLASS
#include <iostream>
using namespace std;

const int stack_size = 100;

class stack
{
private:
card data [stack_size]; // array holding the stack
int top; // index of the top of the stack
public:
stack ();
void push (char item, int r); // pushes item on top of stack
card pop (); // removes the item from the top of
// the stack and returns it
bool full (); // returns true if the stack is full
bool empty (); // returns true if the stack is empty
void print (); // prints the content of stack
};

stack::stack ()
{
top = -1;
}

void stack::push (char item, int r)
{
if (full ())
{
cout << "\n\nStack Error: Trying to push on a full stack";
cout << "\nTry to push the value" << item;
}
else // OK to add the element
{
top++;
data[top].suit = item;
data[top].rank = r;
}
}

card stack::pop ()
{
if (empty ())
{
cout << "\n\nStack error: trying to pop an empty stack";
cout << "\nReturning a ?";
return '?';
}
else // OK to pop the stack
{
top--;
return data[top + 1];
}
}

bool stack::full ()
{
return top == stack_size - 1;
}

bool stack::empty ()
{
return top == -1;
}

void stack::print()
{
for(int i=0; i<stack_size; i++)
{
   cout<<"\nSuit : "<< data[i].suit << " Rank : " << data[i].rank;
}
}


>

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
66
67
68
69
70
//MAIN PROGRAM

void make_deck(stack& deck)
{
int i;
for(i=0; i<13; i++)
{
   deck.data[i].suit = 'h';
   deck.data[i].rank = i+1;
}

for(i=13; i<26; i++)
{
   deck.data[i].suit = 'd';
   deck.data[i].rank = i+1;
}

for(i=26; i<39; i++)
{
   deck.data[i].suit = 'c';
   deck.data[i].rank = i+1;
}

for(i=39; i<52; i++)
{
   deck.data[i].suit = 's';
   deck.data[i].rank = i+1;
}
}

void mix_deck(stack &deck)
{
stack temp1, temp2;
int i, cnt1=0, cnt2=0;
card cTmp;
while(!deck.empty())
{
   cTmp = deck.pop();
   if(i%2 == 0)
   {
   temp1.data[cnt1++].suit = cTmp.suit;
   temp1.data[cnt1++].rank = cTmp.rank;
   }
   else
   {
   temp2.data[cnt2++].suit = cTmp.suit;
   temp2.data[cnt2++].rank = cTmp.rank;
   }
}

while(!temp1.empty())
{
   cTmp = temp1.pop();
   deck.push(cTmp.suit, cTmp.rank);
}
while(!temp2.empty())
{
   cTmp = temp2.pop();
   deck.push(cTmp.suit, cTmp.rank);
}
}

int main()
{
stack deck;
make_deck(deck);
mix_deck(deck);
deck.print();
return 0;
}

Output:

The original deck is:

King of ♦

Queen of ♦

Jack of ♦

10 of ♦

9 of ♦

8 of ♦

7 of ♦

6 of ♦

5 of ♦

4 of ♦

3 of ♦

2 of ♦

Ace of ♦

King of ♣

Queen of ♣

Jack of ♣

10 of ♣

9 of ♣

8 of ♣

7 of ♣

6 of ♣

5 of ♣

4 of ♣

3 of ♣

2 of ♣

Ace of ♣

King of ♥

Queen of ♥

Jack of ♥

10 of ♥

9 of ♥

8 of ♥

7 of ♥

6 of ♥

5 of ♥

4 of ♥

3 of ♥

2 of ♥

Ace of ♥

King of ♠

Queen of ♠

Jack of ♠

10 of ♠

9 of ♠

8 of ♠

7 of ♠

6 of ♠

5 of ♠

4 of ♠

3 of ♠

2 of ♠

Ace of ♠

The mixed deck is:

4 of ♠

King of ♦

9 of ♦

3 of ♠

4 of ♣

6 of ♠

Ace of ♥

8 of ♦

2 of ♠

3 of ♥

Queen of ♦

7 of ♥

5 of ♣

9 of ♣

Queen of ♠

7 of ♦

7 of ♠

Ace of ♦

7 of ♣

Jack of ♦

5 of ♦

4 of ♥

9 of ♠

10 of ♣

10 of ♦

10 of ♥

King of ♠

2 of ♥

9 of ♥

5 of ♠

Queen of ♣

Queen of ♥

Jack of ♣

4 of ♦

8 of ♥

King of ♥

3 of ♣

2 of ♦

6 of ♥

6 of ♣

10 of ♠

8 of ♠

6 of ♦

5 of ♥

2 of ♣

Jack of ♥

Ace of ♠

8 of ♣

King of ♣

Jack of ♠

Ace of ♣

3 of ♦

Last edited on
You need to #include <> your stack and card classes so Main can see them
1
2
3
#include "stack.h"

void make_deck(stack& deck)

Like this because it gives me more errors after i do it
Yea your code is all kinds of messed up. Try to simplify it and get it to compile before you add heaps of crap.
The 3 errors i get are all on main

error: variable ore field 'make_deck' declared void
error: 'stack' was not declared in this scope
error 'deck' was not declared in this scope

when i compile and build
Is this for Linux or Windows/Visual Studio? Because half your shit doesn't work on Windows with GCC.

You can simplify greatly.
e.g
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 <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <clocale>

using namespace std;

char suits[] = { 'H', 'D', 'C', 'S' };
string possible_cards[] = { "1", "2", "3", "4", "5", "6", "7",
              "8", "9", "10", "J", "Q", "K", "A"};

// class
class Card {
public:
  // constructor
  Card(char suit, string value) : suit_(suit), value_(value) { };

  // print our value to screen
  void Print() {
    cout << suit_ << value_ << endl;
  }

private:
  // members
  char suit_;
  string value_;
};

// class
class Deck {
public:
  // constructor
  Deck() {
    for (char suit : suits) {
      for (string card : possible_cards)
        cards_.push_back(Card(suit, card));
    }
  }

  // accessors
  vector<Card>& cards() { return cards_; }

private:
  // members
  vector<Card> cards_;
};

/**
 * Main method
 */
int main() {
  Deck new_deck;
  cout << "Original Order:" << endl;
  for (Card card : new_deck.cards())
    card.Print();
}
I got to use the card and stack headers its for a class i take and im using code blocks on windows psshhh
I wish it was that easy
The code I pasted compiles and runs on MinGW on Windows.
I have no idea what to do
Start by giving each of your files (except your main() one, altho it wouldn't hurt) include guards. Be sure your stack.h includes card.h b/c stack uses the datatype "card".

Also your mix_deck and make_deck functions both try to access the private members of the stack they operate on. This is forbidden unless they're friended by stack. Since you prolly don't want to that, try making these funcs be member funcions.

On top of that, your mix_deck function increments cnt1 and cnt2 2x each, starting at line 41 of MAIN PROGRAM, it should be 1x each, otherwise you change the next card too and eventually get an out of bounds array index.
Topic archived. No new replies allowed.