954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C++ program help.

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?

Undermine
Light Poster
25 posts since Nov 2008
Reputation Points: 41
Solved Threads: 2
 

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

Laiq Ahmed
Junior Poster
148 posts since Jun 2006
Reputation Points: 113
Solved Threads: 20
 

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?

Undermine
Light Poster
25 posts since Nov 2008
Reputation Points: 41
Solved Threads: 2
 

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

Laiq Ahmed
Junior Poster
148 posts since Jun 2006
Reputation Points: 113
Solved Threads: 20
 

quick problem i get like this:

no match for 'std::operator<< [with _Traits = std::char_traits](((std::basic_ostream >&)(&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]

and i have absolute 0 idea what that means

Undermine
Light Poster
25 posts since Nov 2008
Reputation Points: 41
Solved Threads: 2
 

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 :).

Laiq Ahmed
Junior Poster
148 posts since Jun 2006
Reputation Points: 113
Solved Threads: 20
 

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?

Undermine
Light Poster
25 posts since Nov 2008
Reputation Points: 41
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You