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;
}
}
}
}

New Topic/Question
Reply




MultiQuote




|