5 Replies - 3674 Views - Last Post: 23 October 2008 - 07:54 AM Rate Topic: -----

#1 burnik  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-October 08

blackjack program

Posted 16 October 2008 - 10:07 PM

Hi,

This is my first semester with programming. My final project is a simple blackjack program. I've got it to deal the cards but I'm stuck with the rules for hitting, staying, and dealing another card for the dealer after the player is done and stays. Also, don't know how to apply the rules for Aces whether to count it as 1 or 11. The professor made it simple for us by not having multiple decks, just one deck and resets every game, and its just the dealer and a player.
Hope someone can help me. I would appreciate it. Thanks.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>

using namespace std;

void DealNCards (float& runtotalu, float& runtotald, int num, int userdealer, string yourname, int list1[], int list2[]);

int main ()

{
 int list1[12];
 int list2[12];
 bool endgame;
 string yourname;
 string yourname1;
 char ans2;
 float banktotal;
 float bet;
 cout << "Enter your name  "  << endl;
 cin >> yourname1;
 cout << endl;
 cout << "Enter how much total money do you want to play with? " << endl;
 cin >> banktotal;
 cout << endl;
 // Placebet(yourname1,bet, banktotal);
 int userdealer;
 int index1;
 int num;
 float runtotalu = 0;
 float runtotald = 0;
 // If userdealer = 0 then hand is from user
 // If userdealer = 1 then hand is from dealer
 // 2 initial cards;
 num = 2;
 userdealer = 1;
 yourname = "dealer";

 cout << "			 DEALER						   " << endl;
 cout << "											  " << endl;
 DealNCards (runtotalu, runtotald, num, userdealer, yourname, list1,list2);
 cout << endl << endl;
 cout << endl << endl;
 cout << "			 PLAYER = " << yourname1 << "	 " << endl << endl;
 cout << endl;
 userdealer = 0;
 endgame = true;
 yourname = yourname1;

 DealNCards (runtotalu, runtotald, num, userdealer, yourname,list1,list2);
 
 return 0;
}

void DealNCards (float& runtotalu, float& runtotald, int num, int userdealer, string yourname, int list1[], int list2[])
{
 string Hearts;
 string Spades;
 string Diamonds;
 string Clubs;
 string Jack;
 string Queen;
 string King;
 string Ace;
 string Card;
 string Suit;
 Hearts = "Hearts";
 Spades = "Spades";
 Diamonds = "Diamonds";
 Clubs = "Clubs";
 Jack = "Jack";
 Queen = "Queen";
 King = "King";
 Ace = "Ace";

 int val;
 int val1 = 0;
 int count;
 int list [5000];
 int listcounter = 0;

 for (count = 1; count <= num; count++)
 {
	val=0;
	list[count] = (rand () + time (0) ) % 52+1; 
	if ( list[count] >=1 &&  list [count] <= 13 )  
	Suit = Hearts;
	else if ( list[count] >=14 &&  list [count] <= 26 ) 
	Suit = Clubs;
	else if ( list[count] >=27 &&  list [count] <= 39 )
	Suit = Diamonds;
	else
	Suit = Spades;

	if ( list[count] == 1 || list[count] == 14 || list[count] == 27 || list[count] == 40)
	{
	val1 = 1;
	Card = Ace;
	}
	if ( list[count] == 11 || list[count] == 24 || list[count] == 37 || list[count] == 50)
	{
	val1 = 10;
	Card = Jack;
	}
	if ( list[count] == 12 || list[count] == 25 || list[count] == 38 || list[count] == 51)
	{
	val1 = 10;
	Card = Queen;
	}
	if ( list[count] == 13 || list[count] == 26 || list[count] == 39 || list[count] == 52)
	{
	val1 = 10;
	Card = King;
	}
	if ( list[count] >= 2 && list[count] <= 10)
	val = list[count];
	if ( list[count] >= 15 && list[count] <= 23)
	val = list[count] - 13;
	if ( list[count] >= 28 && list[count] <= 36)
	val = list[count] - 26;
	if ( list[count] >= 41 && list[count] <= 49)
	val = list[count] - 39;
  
	if ( val != 0)
	{  
	   // cout << "Card drawn is  " << val << " " << Suit << endl;
	   if ( yourname != "dealer" )
	   {
	   list1[listcounter] = val; 
	   listcounter=listcounter+1;
	   runtotalu=runtotalu+val;
	   cout << "Card drawn is  " << val << " " << Suit << endl;
	   }
	   else
	   {
	   list2[listcounter] = val;
	   listcounter = listcounter+1;
	   runtotald=runtotald+val;
		  if (count == 1)
		  cout << "Card drawn is  " << val << " " << Suit << endl;
		  else
		  cout << "Card drawn is  Down Card  " << endl;
	   }
	}
	else
	{
	   // cout << "Card drawn is  " << Card << " " << Suit << endl;
	   if (yourname != "dealer")
	   {
	   list1[listcounter] = val1; 
	   listcounter=listcounter+1;
	   runtotalu=runtotalu+val1;
	   cout << "Card drawn is  " << Card << " " << Suit << endl; 
	   }
	   else
	   {
		  if (count == 1)
		  cout << "Card drawn is  " << Card << " " << Suit << endl;
		  else
		  cout << "Card drawn is a Down Card  " << endl;
	   list2[listcounter] = val1;
	   listcounter = listcounter+1;
	   runtotald = runtotald+val1;
		 
	   }
	}
   }
 }



Is This A Good Question/Topic? 0
  • +

Replies To: blackjack program

#2 asadullah.ansari  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 11
  • Joined: 16-January 08

Re: blackjack program

Posted 16 October 2008 - 10:18 PM

View Postburnik, on 16 Oct, 2008 - 10:07 PM, said:

Hi,

This is my first semester with programming. My final project is a simple blackjack program. I've got it to deal the cards but I'm stuck with the rules for hitting, staying, and dealing another card for the dealer after the player is done and stays. Also, don't know how to apply the rules for Aces whether to count it as 1 or 11. The professor made it simple for us by not having multiple decks, just one deck and resets every game, and its just the dealer and a player.
Hope someone can help me. I would appreciate it. Thanks.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>

using namespace std;

void DealNCards (float& runtotalu, float& runtotald, int num, int userdealer, string yourname, int list1[], int list2[]);

int main ()

{
 int list1[12];
 int list2[12];
 bool endgame;
 string yourname;
 string yourname1;
 char ans2;
 float banktotal;
 float bet;
 cout << "Enter your name  "  << endl;
 cin >> yourname1;
 cout << endl;
 cout << "Enter how much total money do you want to play with? " << endl;
 cin >> banktotal;
 cout << endl;
 // Placebet(yourname1,bet, banktotal);
 int userdealer;
 int index1;
 int num;
 float runtotalu = 0;
 float runtotald = 0;
 // If userdealer = 0 then hand is from user
 // If userdealer = 1 then hand is from dealer
 // 2 initial cards;
 num = 2;
 userdealer = 1;
 yourname = "dealer";

 cout << "			 DEALER						   " << endl;
 cout << "											  " << endl;
 DealNCards (runtotalu, runtotald, num, userdealer, yourname, list1,list2);
 cout << endl << endl;
 cout << endl << endl;
 cout << "			 PLAYER = " << yourname1 << "	 " << endl << endl;
 cout << endl;
 userdealer = 0;
 endgame = true;
 yourname = yourname1;

 DealNCards (runtotalu, runtotald, num, userdealer, yourname,list1,list2);
 
 return 0;
}

void DealNCards (float& runtotalu, float& runtotald, int num, int userdealer, string yourname, int list1[], int list2[])
{
 string Hearts;
 string Spades;
 string Diamonds;
 string Clubs;
 string Jack;
 string Queen;
 string King;
 string Ace;
 string Card;
 string Suit;
 Hearts = "Hearts";
 Spades = "Spades";
 Diamonds = "Diamonds";
 Clubs = "Clubs";
 Jack = "Jack";
 Queen = "Queen";
 King = "King";
 Ace = "Ace";

 int val;
 int val1 = 0;
 int count;
 int list [5000];
 int listcounter = 0;

 for (count = 1; count <= num; count++)
 {
	val=0;
	list[count] = (rand () + time (0) ) % 52+1; 
	if ( list[count] >=1 &&  list [count] <= 13 )  
	Suit = Hearts;
	else if ( list[count] >=14 &&  list [count] <= 26 ) 
	Suit = Clubs;
	else if ( list[count] >=27 &&  list [count] <= 39 )
	Suit = Diamonds;
	else
	Suit = Spades;

	if ( list[count] == 1 || list[count] == 14 || list[count] == 27 || list[count] == 40)
	{
	val1 = 1;
	Card = Ace;
	}
	if ( list[count] == 11 || list[count] == 24 || list[count] == 37 || list[count] == 50)
	{
	val1 = 10;
	Card = Jack;
	}
	if ( list[count] == 12 || list[count] == 25 || list[count] == 38 || list[count] == 51)
	{
	val1 = 10;
	Card = Queen;
	}
	if ( list[count] == 13 || list[count] == 26 || list[count] == 39 || list[count] == 52)
	{
	val1 = 10;
	Card = King;
	}
	if ( list[count] >= 2 && list[count] <= 10)
	val = list[count];
	if ( list[count] >= 15 && list[count] <= 23)
	val = list[count] - 13;
	if ( list[count] >= 28 && list[count] <= 36)
	val = list[count] - 26;
	if ( list[count] >= 41 && list[count] <= 49)
	val = list[count] - 39;
  
	if ( val != 0)
	{  
	   // cout << "Card drawn is  " << val << " " << Suit << endl;
	   if ( yourname != "dealer" )
	   {
	   list1[listcounter] = val; 
	   listcounter=listcounter+1;
	   runtotalu=runtotalu+val;
	   cout << "Card drawn is  " << val << " " << Suit << endl;
	   }
	   else
	   {
	   list2[listcounter] = val;
	   listcounter = listcounter+1;
	   runtotald=runtotald+val;
		  if (count == 1)
		  cout << "Card drawn is  " << val << " " << Suit << endl;
		  else
		  cout << "Card drawn is  Down Card  " << endl;
	   }
	}
	else
	{
	   // cout << "Card drawn is  " << Card << " " << Suit << endl;
	   if (yourname != "dealer")
	   {
	   list1[listcounter] = val1; 
	   listcounter=listcounter+1;
	   runtotalu=runtotalu+val1;
	   cout << "Card drawn is  " << Card << " " << Suit << endl; 
	   }
	   else
	   {
		  if (count == 1)
		  cout << "Card drawn is  " << Card << " " << Suit << endl;
		  else
		  cout << "Card drawn is a Down Card  " << endl;
	   list2[listcounter] = val1;
	   listcounter = listcounter+1;
	   runtotald = runtotald+val1;
		 
	   }
	}
   }
 }








You can find detail on
http://www.planet-so...p...88&lngWId=3
Was This Post Helpful? 0
  • +
  • -

#3 burnik  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-October 08

Re: blackjack program

Posted 16 October 2008 - 11:16 PM

You can find detail on
http://www.planet-so...p...88&lngWId=3
[/quote]

This is nice and all but I need help with my program. It has to have betting and it needs to keep 1 dealer card unknown (face down). Only after the player stands when it should display the dealers cards.
Was This Post Helpful? 0
  • +
  • -

#4 gusdewa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 13-October 08

Re: blackjack program

Posted 17 October 2008 - 02:22 PM

View Postasadullah.ansari, on 16 Oct, 2008 - 10:18 PM, said:

View Postburnik, on 16 Oct, 2008 - 10:07 PM, said:

Hi,

This is my first semester with programming. My final project is a simple blackjack program. I've got it to deal the cards but I'm stuck with the rules for hitting, staying, and dealing another card for the dealer after the player is done and stays. Also, don't know how to apply the rules for Aces whether to count it as 1 or 11. The professor made it simple for us by not having multiple decks, just one deck and resets every game, and its just the dealer and a player.
Hope someone can help me. I would appreciate it. Thanks.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>

using namespace std;

void DealNCards (float& runtotalu, float& runtotald, int num, int userdealer, string yourname, int list1[], int list2[]);

int main ()

{
 int list1[12];
 int list2[12];
 bool endgame;
 string yourname;
 string yourname1;
 char ans2;
 float banktotal;
 float bet;
 cout << "Enter your name  "  << endl;
 cin >> yourname1;
 cout << endl;
 cout << "Enter how much total money do you want to play with? " << endl;
 cin >> banktotal;
 cout << endl;
 // Placebet(yourname1,bet, banktotal);
 int userdealer;
 int index1;
 int num;
 float runtotalu = 0;
 float runtotald = 0;
 // If userdealer = 0 then hand is from user
 // If userdealer = 1 then hand is from dealer
 // 2 initial cards;
 num = 2;
 userdealer = 1;
 yourname = "dealer";

 cout << "			 DEALER						   " << endl;
 cout << "											  " << endl;
 DealNCards (runtotalu, runtotald, num, userdealer, yourname, list1,list2);
 cout << endl << endl;
 cout << endl << endl;
 cout << "			 PLAYER = " << yourname1 << "	 " << endl << endl;
 cout << endl;
 userdealer = 0;
 endgame = true;
 yourname = yourname1;

 DealNCards (runtotalu, runtotald, num, userdealer, yourname,list1,list2);
 
 return 0;
}

void DealNCards (float& runtotalu, float& runtotald, int num, int userdealer, string yourname, int list1[], int list2[])
{
 string Hearts;
 string Spades;
 string Diamonds;
 string Clubs;
 string Jack;
 string Queen;
 string King;
 string Ace;
 string Card;
 string Suit;
 Hearts = "Hearts";
 Spades = "Spades";
 Diamonds = "Diamonds";
 Clubs = "Clubs";
 Jack = "Jack";
 Queen = "Queen";
 King = "King";
 Ace = "Ace";

 int val;
 int val1 = 0;
 int count;
 int list [5000];
 int listcounter = 0;

 for (count = 1; count <= num; count++)
 {
	val=0;
	list[count] = (rand () + time (0) ) % 52+1; 
	if ( list[count] >=1 &&  list [count] <= 13 )  
	Suit = Hearts;
	else if ( list[count] >=14 &&  list [count] <= 26 ) 
	Suit = Clubs;
	else if ( list[count] >=27 &&  list [count] <= 39 )
	Suit = Diamonds;
	else
	Suit = Spades;

	if ( list[count] == 1 || list[count] == 14 || list[count] == 27 || list[count] == 40)
	{
	val1 = 1;
	Card = Ace;
	}
	if ( list[count] == 11 || list[count] == 24 || list[count] == 37 || list[count] == 50)
	{
	val1 = 10;
	Card = Jack;
	}
	if ( list[count] == 12 || list[count] == 25 || list[count] == 38 || list[count] == 51)
	{
	val1 = 10;
	Card = Queen;
	}
	if ( list[count] == 13 || list[count] == 26 || list[count] == 39 || list[count] == 52)
	{
	val1 = 10;
	Card = King;
	}
	if ( list[count] >= 2 && list[count] <= 10)
	val = list[count];
	if ( list[count] >= 15 && list[count] <= 23)
	val = list[count] - 13;
	if ( list[count] >= 28 && list[count] <= 36)
	val = list[count] - 26;
	if ( list[count] >= 41 && list[count] <= 49)
	val = list[count] - 39;
  
	if ( val != 0)
	{  
	   // cout << "Card drawn is  " << val << " " << Suit << endl;
	   if ( yourname != "dealer" )
	   {
	   list1[listcounter] = val; 
	   listcounter=listcounter+1;
	   runtotalu=runtotalu+val;
	   cout << "Card drawn is  " << val << " " << Suit << endl;
	   }
	   else
	   {
	   list2[listcounter] = val;
	   listcounter = listcounter+1;
	   runtotald=runtotald+val;
		  if (count == 1)
		  cout << "Card drawn is  " << val << " " << Suit << endl;
		  else
		  cout << "Card drawn is  Down Card  " << endl;
	   }
	}
	else
	{
	   // cout << "Card drawn is  " << Card << " " << Suit << endl;
	   if (yourname != "dealer")
	   {
	   list1[listcounter] = val1; 
	   listcounter=listcounter+1;
	   runtotalu=runtotalu+val1;
	   cout << "Card drawn is  " << Card << " " << Suit << endl; 
	   }
	   else
	   {
		  if (count == 1)
		  cout << "Card drawn is  " << Card << " " << Suit << endl;
		  else
		  cout << "Card drawn is a Down Card  " << endl;
	   list2[listcounter] = val1;
	   listcounter = listcounter+1;
	   runtotald = runtotald+val1;
		 
	   }
	}
   }
 }








You can find detail on
http://www.planet-so...p...88&lngWId=3


Hey.. are you an ITS-Informatics Student ?He3.. I've got you...
Was This Post Helpful? 0
  • +
  • -

#5 burnik  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-October 08

Re: blackjack program

Posted 18 October 2008 - 12:07 PM

Hey.. are you an ITS-Informatics Student ?He3.. I've got you...
[/quote]

Yeah, help me out, man ;)
Was This Post Helpful? 0
  • +
  • -

#6 jderecho  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 26
  • Joined: 23-July 08

Re: blackjack program

Posted 23 October 2008 - 07:54 AM

To answer to your original questions, the dealer has a simple rule: Hit on 16 or less and stand on 17 or more.

The rule in calculating the value of Aces is simple, assume 11 for an Ace unless it causes your hand to bust. For example, if you are delt two Aces: using 11 each they would total 22 which is a bust, so you assume that one has a value of one and the other is eleven for a total of twelve. If you hit this hand and get a ten card, then both would be valued at one each, and you still have a hand value of twelve.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1