HEADER FILE:

#include <string>
using std::string;
class Blackjack
{
  public:    
           
        Blackjack(string);  
        void Shuffle();
        void Intro(string);
        void InitDeck();
        void PrintCard(int);
      //  void Card(int);     
             
             
             
  private:
          
        int deck[52];  //deck of 52 cards.

};

BODY PROGRAM.

#include    <iostream>
#include    <fstream>
#include    <cctype>
#include    <cstdlib>
#include    <ctime>
using namespace std;



#include "bj.h"

Blackjack::Blackjack(string name)
{
    Intro( name );
                      
}
void Blackjack::Intro(string name)
{
cout<<"##############################################################"<<endl;    
cout<<"Program done by" <<  endl;
cout<<"Lets define the basic rules::" << endl;
cout<<"##############################################################"<<endl;
system("PAUSE");

}
void Blackjack::Shuffle()
{
//int deck[52];
srand(time(0));

int b;
for( b = 0; b < 52; b++ ){
   deck[b] = b+1;
}

int t;
for (int i=0; i<(52-1); i++)
{
int j = i + (rand() % (52-i));
int temp = deck[i];deck[i]=deck[j];deck[j]= temp;
}

int card1=deck[0];
int card2=deck[1];
int card3=deck[2];
int card4=deck[3];

cout << "human has "<< deck[0] << " " << deck[2]<< endl;
cout<<" computer has" << deck[1] <<" " << deck[3] << endl;

}


void Blackjack::PrintCard(int temp)
 {

	// Print Rank
	const int kiRank = (temp % 13);
	if (kiRank == 0) {
		cout << 'A';
	} else if (kiRank < 9) {
		cout << (kiRank + 1);
	} else if (kiRank == 9) {
		cout << 'T';
	} else if (kiRank == 10) {
		cout << 'J';
	} else if (kiRank == 11) {
		cout << 'Q';
	} else {
		cout << 'K';
	}
	// Print Suit
	const int kiSuit = (temp/13);
	if (kiSuit == 0) {
		cout << 'C';
	} else if (kiSuit == 1) {
		cout << 'D';
	} else if (kiSuit == 2) {
		cout << 'H';
	} else {
		cout << 'S';
	}
}

MAIN PROGRAM

#include<iostream>


#include "bj.h"


//-------------------------------------------------------------------

int main(int argc, char *argv[])
{ 
    
Blackjack myBlackjack("welcome to blackjack");

myBlackjack.Shuffle();
myBlackjack.PrintCard();
//myBlackjack.InitDeck();



system("PAUSE");

return 0;
}


//-------------------------------------------------------------------

I'm pretty much an idiot in C++, i get the following errors..
no matching function for call to `Blackjack::PrintCard()'
candidates are: void Blackjack::PrintCard(int)

Also will that even properly associate the random generated # with it's corresponding card value?

Recommended Answers

All 6 Replies

PrintCard requires integer parameter and you are not providing one, and the error description shows this as well.

Remove this myBlackjack.PrintCard(); with myBlackjack.PrintCard(10); it will print the corresponding card and suit

Ok so now the problem becomes that i need to send to printcard whatever value the shuffler comes up with each time it shuffles the deck, how do i do this?

Modify your Shuffle Function and call the PrintCard Function within it

Change the Following Code Segment

//remove the following four lines.
int card1=deck[0];     
int card2=deck[1];    
int card3=deck[2];
int card4=deck[3];

cout << "human has "<< deck[0] << " " << deck[2]<< endl;
cout<<" computer has" << deck[1] <<" " << deck[3] << endl;

to

cout << "human has "<< PrintCard(deck[0]) << " " << PrintCard(deck[2])<< endl;
cout<<" computer has" << PrintCard(deck[1]) <<" " << PrintCard(deck[3]) << endl;

Hope this helps

quick problem i get like this:

no match for 'std::operator<< [with _Traits = std::char_traits<char>](((std::basic_ostream<char, std::char_traits<char> >&)(&std::cout)), ((const char*)"human has ")) << ((Blackjack*)this)->Blackjack::PrintCard(((Blackjack*)this)->Blackjack::deck[0])'

note C:\Dev-Cpp\include\c++\3.4.2\bits\ostream.tcc:63 candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>&(*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]

and i have absolute 0 idea what that means

sorry my mistake, I didn't see the signature of PrintCard

remove your two cout statements with

#
cout << "human has "<< PrintCard(deck[0]) << " " << PrintCard(deck[2])<< endl;
#
cout<<" computer has" << PrintCard(deck[1]) <<" " << PrintCard(deck[3]) << endl;

with

PrintCard(deck[0]);
PrintCard(deck[1]) ;
// whatever card you want to print.

Hope this works :).

Hey thanks you've been a giant help. 2 more questions while you are here =P

What do i sent the PrintCard from main it is asking for an int value?

and my next function will be to assign value to the cards, the problem is how is it going to refer back to the shuffle and printcard constructors?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.