finding whats wrong with c++ program

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

#include <cstdlib>
#include <cctype> //Required for toupper()
#include <string> //Required for string
#include <iostream> //require for ostream
using namespace std;


Card::Card():rank(2), suit('S')
{
}
Card::Card(char ch, int i): rank(i)
{
 suit=(toupper(ch));
}



//Formatted display method
void Card::displayCard(ostream& out) const
{
   string suitString;
   //establish suit string
   //Constructors and mutators gaurantee uppercase suit
   switch(suit){
    case 'S':
      suitString = "Spades";
      break;
    case 'H':
      suitString = "Hearts";
      break;
    case 'D':
      suitString = "Diamonds";
      break;
    case 'C':
      suitString = "Clubs";
      break;
    default:
      suitString = "Not A Suit";
   }//end switch suit

   if(rank >= 2 && rank < 11)
   { //output the rank and suit string
     out << rank << " of " << suitString;
   } //end if
   else
   { //Establish rank string(ace, king, queen or jack)
     switch(rank){
       case 11: 
         out << "JACK of " << suitString;
         break;
       case 12: 
         out << "QUEEN of " << suitString;
         break;
       case 13: 
         out << "KING of " << suitString;
         break;
       case 14: 
         out << "ACE of " << suitString;
         break;
      }//end switch rank
   }//end else
   return;
 }//end Display
 
 void Card::randomDraw(){
     
     
 }
}




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
#ifndef CARD_H
#define CARD_H
#include <iostream> //Required for ostream
#include <cstdlib>
using namespace std;

class Card {
      public:
   //Constructors
     Card(); //Default 
     Card(char aSuit, 
          int aRank);//parameterized 

   //Accessors
     int getRank() const;
     char getSuit() const;

   //Formatted Display Method
   //Example: if char is 'S' and rank is 11
   //output will be:
   //Jack of Spades
     void displayCard(ostream& outStream) const;
     
     void randomDraw();
     private:
     char suit;
     int rank;
};
#endif  //end compiler directive ifndef 


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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <iostream>
 #include <algorithm>
 #include<ctime>
 # include "card.h"
 #include "carddeck.h"
 #include <cstdlib>
//  #include "randomdraw.h"
//  #include "isempty.h"


bool CardDeck::isempty(){
    
 void Card::randomDraw(
    
}

void CardDeck::randomDraw(){
    
    void Card::randomDraw(
    
    
}


using namespace std;
int main()
{


 static const char *ranks[] =
 {
     "Ace", "Two", "Three", "Four", "Five", "Six", "Seven",
     "Eight", "Nine", "Ten", "Jack", "Queen", "King"
 };


 static const char *suits[] =
 {
     "Spades", "Clubs", "Diamonds", "Hearts"
 };

int print_card(int n)
 {
 int count=0;
 int j,i;
 int sum=0;
 i=n/13;
 j=0;
 if(count==4)
 {
   cout<<"Number of picks: "<<sum<<endl;
   return 0;
 }
 else
 {
   if(j!=i)
   {
    if(n/13==4 && count<5)
    {
     cout << ranks[n % 13] << " of "<< suits[0] << endl;
     count++;
     sum++;
    }
    else if(count<5)
    {
     cout << ranks[n % 13] << " of "<< suits[n / 13] << endl;
     count++;
     sum++;
    }
    
    
    j=i;
   }
 }
    
 }

int main()
 {
     srand((unsigned int)time(NULL));
    
    // initialize you card class first
    CardDeck cd;
    
    
    
    
    
    
    int deck[52];

    // Prime, shuffle, dump
     for (int i=0;i<52;deck[i++]=i);
     random_shuffle(deck, deck+52);
     for_each(deck, deck+52, print_card);

     system ("pause");
    return 0;
 }



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
#include "CardDeck.h"
#include <cstdlib>
#include <ctime> //Required for time()
#include <algorithm> //Required for random_shuffle()
using namespace std;

CardDeck::CardDeck()
{
  /* 13 cards in each suit.           */
  /* push_back recieves 52 new cards. */
  for(int i= 2; i<15; ++i){
    theDeck.push_back(Card('S',i));
    theDeck.push_back(Card('H',i));
    theDeck.push_back(Card('D',i));
    theDeck.push_back(Card('C',i));
  }
  srand(time(NULL)); //Must seed RNG 1 time!
}

Card CardDeck::draw(){
/* Draw and return one card.       */
  if(theDeck.empty())
  {
    exit(1);
  }
  Card aCard = theDeck.back(); //Draw card.
  theDeck.pop_back();//Remove card.

  //Retain card for shuffle.
  deltCards.push_back(aCard);
  return(aCard);
}

void CardDeck::shuffleDeck(){
 /* Replace drawn cards             */
 for(int i=0; i<deltCards.size(); ++i)
 {
   theDeck.push_back(deltCards[i]);
 }
 
 //Clear the vector.
 deltCards.resize(0);

 //Use the top level function from algorithm.
 random_shuffle(theDeck.begin(), theDeck.end());
}


bool CardDeck::isEmpty(){
}
     
 void Card::randomDraw(){ 

}
   
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef CARDDECK_H
#define CARDDECK_H
/*--------------------------------------*/
/* CardDeck class declaration           */
/* filename: CardDeck.h                 */
#include "Card.h" //Required for Card
#include <vector> //Required for vector */
#include <cstdlib>
using namespace std;

class CardDeck {
public:
  CardDeck();
  void shuffleDeck();
  Card draw();
  bool isEmpty();
private:
  vector<Card>  theDeck;
  vector<Card>  deltCards;
};
/*---------------------------------------*/
#endif 
Last edited on
Can you be more specific about the error(s)?

You have two main functions in what you've posted here. There should only be one.
line 58 C:\Dev-Cpp\carddeck.cpp expected declaration before '}' token
and then there is a makefile error: E:\Makefile.win [Build Error] [C:/Dev-Cpp/carddeck.o] Error 1
I don't see a line 58 in the carddeck you posted here - do you know which line it would be in the posted code?


Maybe someone with more makefile experience can weigh in on that error.
You have unmatched closing bracked on that line. delete it.
Topic archived. No new replies allowed.