Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,228 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,890 people online right now. Registration is fast and FREE... Join Now!




Black Jack Problems

2 Pages V  1 2 >  
Reply to this topicStart new topic

Black Jack Problems, Need help on this

Elende
15 Feb, 2007 - 11:25 AM
Post #1

New D.I.C Head
*

Joined: 13 Feb, 2007
Posts: 14


My Contributions
Ok the ace problem was solved, now if anyone could help with incorporating graphics of the cards, i would greatly appriceate(sp) it.

//the program starts here


#include <iostream>
#include <ctime>
#include <card>

using namespace std;

int main(void)
{
int turn = 0;
int dealer =0;
int player1 =0;
int player2 =0;
int cardvalue =0;
int ranTotal =0;
int hit=0;
int bet=0;
int cashTotal1=0;
int cashTotal2=0;
int choice=0;
int ace=o;
int totalparticipants=0;
int howmanycards =0;
int cardsuit=o;
int Faceup =0;
int Facedown =0;
srand(time(0));

cout << "BLACK JACK" << endl;


//betting for player1
cout << "Player 1" << endl;
cashTotal1 = (500);
cout << cashTotal1 << endl;
// cashTotal1 += bet;
// cashTotal1 -= bet;
cout << "Enter in bet" << endl;
cin >> bet;


//betting for player2
cout << "Player 2" << endl;
cashTotal2 = (500);
cout << cashTotal2 << endl;
// cashTotal2 += bet;
// cashTotal2 -= bet;
cout << "Enter in bet" << endl;
cin >> bet;

//end bet


void card::Faceup()
{
status = 1;
}

void card::Facedown()
{
status = 2;
}


//cardvalue
value card::cardvalue();
//cardsuit 1 = hearts, 2 = diamonds, 3 = clubs, 4 = spades
suit card::cardsuit(rand()%10)+2;


//Player 1
cout << "Player 1" << endl;
cout << "___" << endl;
for(int i= 0; i < 2; i++)
{
ranTotal = (rand()%10)+2;


if(ranTotal==11) //ace
player1 += ranTotal;
if(player1>21)
player1 -=10; //if over 21, subtract 10


cout << "The card value was: "<< ranTotal << endl;
player1 += ranTotal;
}
do
{
cout << "Player 1 has a total of: " << player1 << endl;
cout << "Would you like a hit, if yes enter \"1\" else enter \"2\" : ";
cin >> hit;

cardvalue=ranTotal; //declares value of card
cout << cardvalue << endl;

if(hit == 1 && player1 <= 21)
{
ranTotal = (rand()%10)+2;
player1 += ranTotal;
if(player1 > 21)
{
cout << " You have lost!" << endl;
break;

}
}

}while(hit == 1);

//Player 2
cout << "Player 2" << endl;
cout << "___" << endl;
for(int i= 0; i < 2; i++)
{
ranTotal = (rand()%10)+2;

if(ranTotal==11) //ace
player2 += ranTotal;
if(player2>21)
player2 -=10; //if over 21, subtract 10

cout << "The card value was: "<< ranTotal << endl;
player2 += ranTotal;
}
do
{
cout << "Player 2 has a total of: " << player2 << endl;
cout << "Would you like a hit, if yes enter \"1\" else enter \"2\" : ";
cin >> hit;
if(hit == 1 && player2 <= 21)
{
ranTotal = (rand()%10)+2;
player2 += ranTotal;
if(player2 > 21)
{
cout << " player2 lost!" << endl;
break;

}
}

//bet consiquence


cout << "Player 1" << endl;
cout << cashTotal1 << endl;
{
if(player1 > player2)
cashTotal1 += bet;

else if(player1 > player2)
{
cashTotal1 -= bet;
}

cout << "Player 2" << endl;
cout << cashTotal2 << endl;

if(player2 > player1)
cashTotal2 += bet;

else if(player2 > player1)
{
cashTotal2 -= bet;
}
}
//ending outcome
}while(hit == 1);
if(player1 < 22 && player2 < 22)
{
if(player1 > player2)
{
cout << "Win by player 1";
}
else if(player1 < player2)
{
cout << "Win by player 2";
}
else if(player2 == player1)
{
cout << "Tie";
}
else
{
cout << "error!! ";
}
}
else

return 0;
}






Anyones help is loved



This post has been edited by Elende: 15 Feb, 2007 - 01:11 PM
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Black Jack Problems
15 Feb, 2007 - 11:36 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
Can you provide a description of what is currently happening?
User is online!Profile CardPM
+Quote Post

Elende
RE: Black Jack Problems
15 Feb, 2007 - 11:40 AM
Post #3

New D.I.C Head
*

Joined: 13 Feb, 2007
Posts: 14


My Contributions
i coule add a lot more commets or you could just read this..

this is a black jack game, at first there is bids, then the game goes at this point
//Player 1
cout << "Player 1" << endl;
cout << "___" << endl;
for(int i= 0; i < 2; i++)
{
ranTotal = (rand()%10)+2;

then player2 makes his move then the one with the better score wins

//ending outcome
}while(hit == 1);
if(player1 < 22 && player2 < 22)
{
if(player1 > player2)
{
cout << "Win by player 1";
}
else if(player1 < player2)
{
cout << "Win by player 2";
}
else if(player2 == player1)
{
cout << "Tie";
}
else
{
cout << "error!! ";
}

does that help
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Black Jack Problems
15 Feb, 2007 - 11:45 AM
Post #4

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
Actually, I meant what is the problem with your ace functionality currently. What is happening right now with it when you run the program?
User is online!Profile CardPM
+Quote Post

Elende
RE: Black Jack Problems
15 Feb, 2007 - 11:48 AM
Post #5

New D.I.C Head
*

Joined: 13 Feb, 2007
Posts: 14


My Contributions
QUOTE(Amadeus @ 15 Feb, 2007 - 12:45 PM) *

Actually, I meant what is the problem with your ace functionality currently. What is happening right now with it when you run the program?

its only comes up as a 11 points and is not able to become a 1 point, how do you tell it to change value.

Hey i have only been programing for a couple days actually,
i am a very fast learner
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Black Jack Problems
15 Feb, 2007 - 11:54 AM
Post #6

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
I'm not debating that you are a fast learner, I simply needed to understand the issue.

the value can be changed simply by reassigning it. When do you want it to change? In certain cases, or do you want the user to decide?
User is online!Profile CardPM
+Quote Post

Elende
RE: Black Jack Problems
15 Feb, 2007 - 11:55 AM
Post #7

New D.I.C Head
*

Joined: 13 Feb, 2007
Posts: 14


My Contributions
QUOTE(Amadeus @ 15 Feb, 2007 - 12:54 PM) *

I'm not debating that you are a fast learner, I simply needed to understand the issue.

the value can be changed simply by reassigning it. When do you want it to change? In certain cases, or do you want the user to decide?

i was just informing you i am not experienced

um i what it to always be the value of 11, but if you pass 21 i want the value to become 1.
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Black Jack Problems
15 Feb, 2007 - 12:02 PM
Post #8

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
CODE

if(ranTotal=11)
cout << "You have drawn an ace" << endl;
cin >> ace;
//end of ace
cout << "The card value was: "<< ranTotal << endl;
player1 += ranTotal;

First, for comparison purposes, you will need the equality operator, not the assignment operator.
CODE

if(ranTotal==11)

Second, as you are not allowing the user to decide, you can get rid of the cin statement.

Now you want to check if the addition of the Ace has increased ranTotal past 21...if so, you want the value to be a one.
CODE

if(ranTotal==11)
   player1 += ranTotal;
if(player1>21)
   player1 -=10; //if over 21, subtract 10

User is online!Profile CardPM
+Quote Post

Elende
RE: Black Jack Problems
15 Feb, 2007 - 12:07 PM
Post #9

New D.I.C Head
*

Joined: 13 Feb, 2007
Posts: 14


My Contributions
QUOTE(Amadeus @ 15 Feb, 2007 - 01:02 PM) *

CODE

if(ranTotal=11)
cout << "You have drawn an ace" << endl;
cin >> ace;
//end of ace
cout << "The card value was: "<< ranTotal << endl;
player1 += ranTotal;

First, for comparison purposes, you will need the equality operator, not the assignment operator.
CODE

if(ranTotal==11)

Second, as you are not allowing the user to decide, you can get rid of the cin statement.

Now you want to check if the addition of the Ace has increased ranTotal past 21...if so, you want the value to be a one.
CODE

if(ranTotal==11)
   player1 += ranTotal;
if(player1>21)
   player1 -=10; //if over 21, subtract 10


thank you so much, now if you dont mind could you tell me how to add in the card pictures, i have pictures of what i want but i dont know how to do that

This post has been edited by Elende: 15 Feb, 2007 - 12:09 PM
User is offlineProfile CardPM
+Quote Post

Elende
RE: Black Jack Problems
15 Feb, 2007 - 12:24 PM
Post #10

New D.I.C Head
*

Joined: 13 Feb, 2007
Posts: 14


My Contributions
So i have a problem with getting the cards into the program, i want images but all I have right now is the value of the Cards. How do you place a image in which you have saved into the code.
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Black Jack Problems
15 Feb, 2007 - 12:35 PM
Post #11

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
Threads merged for continuity. Please do not post duplicate threads for the same subject.
User is online!Profile CardPM
+Quote Post

Elende
RE: Black Jack Problems
15 Feb, 2007 - 12:39 PM
Post #12

New D.I.C Head
*

Joined: 13 Feb, 2007
Posts: 14


My Contributions
But the problem is i dont know how to add the cards in the program, i want it that they will be drawn from the deck and the two placed before you, then you could make a dissision on to hit or not. So how do you do that... here is the code, its becoming different from last time...


#include <iostream>
#include <ctime>
#include <card>

using namespace std;

int main(void)
{
int turn = 0;
int dealer =0;
int player1 =0;
int player2 =0;
int cardvalue =0;
int ranTotal =0;
int hit=0;
int bet=0;
int cashTotal1=0;
int cashTotal2=0;
int choice=0;
int ace=o;
int totalparticipants=0;
int howmanycards =0;
int cardsuit=o;
int Faceup =0;
int Facedown =0;
srand(time(0));

cout << "BLACK JACK" << endl;


//betting for player1
cout << "Player 1" << endl;
cashTotal1 = (500);
cout << cashTotal1 << endl;
// cashTotal1 += bet;
// cashTotal1 -= bet;
cout << "Enter in bet" << endl;
cin >> bet;


//betting for player2
cout << "Player 2" << endl;
cashTotal2 = (500);
cout << cashTotal2 << endl;
// cashTotal2 += bet;
// cashTotal2 -= bet;
cout << "Enter in bet" << endl;
cin >> bet;

//end bet


void card::Faceup()
{
status = 1;
}

void card::Facedown()
{
status = 2;
}


//cardvalue
value card::cardvalue();
//cardsuit 1 = hearts, 2 = diamonds, 3 = clubs, 4 = spades
suit card::cardsuit(rand()%10)+2;


//Player 1
cout << "Player 1" << endl;
cout << "___" << endl;
for(int i= 0; i < 2; i++)
{
ranTotal = (rand()%10)+2;


if(ranTotal==11) //ace
player1 += ranTotal;
if(player1>21)
player1 -=10; //if over 21, subtract 10


cout << "The card value was: "<< ranTotal << endl;
player1 += ranTotal;
}
do
{
cout << "Player 1 has a total of: " << player1 << endl;
cout << "Would you like a hit, if yes enter \"1\" else enter \"2\" : ";
cin >> hit;

cardvalue=ranTotal; //declares value of card
cout << cardvalue << endl;

if(hit == 1 && player1 <= 21)
{
ranTotal = (rand()%10)+2;
player1 += ranTotal;
if(player1 > 21)
{
cout << " You have lost!" << endl;
break;

}
}

}while(hit == 1);

//Player 2
cout << "Player 2" << endl;
cout << "___" << endl;
for(int i= 0; i < 2; i++)
{
ranTotal = (rand()%10)+2;

if(ranTotal==11) //ace
player2 += ranTotal;
if(player2>21)
player2 -=10; //if over 21, subtract 10

cout << "The card value was: "<< ranTotal << endl;
player2 += ranTotal;
}
do
{
cout << "Player 2 has a total of: " << player2 << endl;
cout << "Would you like a hit, if yes enter \"1\" else enter \"2\" : ";
cin >> hit;
if(hit == 1 && player2 <= 21)
{
ranTotal = (rand()%10)+2;
player2 += ranTotal;
if(player2 > 21)
{
cout << " player2 lost!" << endl;
break;

}
}

//bet consiquence


cout << "Player 1" << endl;
cout << cashTotal1 << endl;
{
if(player1 > player2)
cashTotal1 += bet;

else if(player1 > player2)
{
cashTotal1 -= bet;
}

cout << "Player 2" << endl;
cout << cashTotal2 << endl;

if(player2 > player1)
cashTotal2 += bet;

else if(player2 > player1)
{
cashTotal2 -= bet;
}
}
//ending outcome
}while(hit == 1);
if(player1 < 22 && player2 < 22)
{
if(player1 > player2)
{
cout << "Win by player 1";
}
else if(player1 < player2)
{
cout << "Win by player 2";
}
else if(player2 == player1)
{
cout << "Tie";
}
else
{
cout << "error!! ";
}
}
else

return 0;
}





User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Reply to this topicStart new topic
Time is now: 12/4/08 03:04PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month