My home work is to write a blackjack program the part i am having trouble with is drawing a random card out of the set my professor is having us use.
#include <iostream>
#include <cstdlib>
using namespace std;
void print_deck(CARD deck[])
{
for (int x = 0; x < 52; x++)
{
print_card(deck[x]);
cout << endl;
}
}
void shuffle_deck(CARD deck[])
{
for (int x = 0; x < 52; x++)
{
int new_index = rand() % 52;
CARD temp = deck[x];
deck[x] = deck[new_index];
deck[new_index] = temp;
}
}
int main()
{
srand(5);
CARD deck[52];
init_deck(deck);
int funds;
int bet;
cout << "*****BlackJack*****" <<endl;
cout << "Please enter starting amount of funds:" << endl;
cin >> funds;
cout << "Place first bet: " << endl;
int x = rand() % 52;
cout << "dealer first card: " << print_card() << endl;
//shuffle_deck(deck);
//print_deck(deck);
}
i want to use the print card function and get a random card then add it to a total? any help please, or use another of the declared functions, to print a card and use the value of that card.
Your code looks like the same code that my teacher gave me. I am currently trying to do my code as well. Here is the code that I have for my dealer and player for initial hand.
Yea broncs we are in the same class lol I have been seeing your posts on here you have a lot of te same problems as I do lol.
With Your next hand code what if it goes past 5 cards say player gets a2 and a4 and wants to hit? I thought we needed to code for that? That's why I want to be able to pull a random card out of deck[] and add it to a total till you say hit 21 or over..
I don't have the code on hand for the error I will post it when I get home from work
Yeah, sorry that code was just what I used for the initial two cards to be dealt. I can give you code for the loops I have for the cards to be pulled but for some reason the cards are being drawn in the wrong order and I can't figure it out. For example they hit and draw a 5 and then a 2 instead of a 2 and then a 5. That's the only problem that I have left to solve.
No problem, if you get yours working today or tomorrow after noon let me know. Mine is due tomorrow. Hopefully I can figure it out or I'll just leave it as it and hope I get some credit for it.
what I hate/love about the class is he gives you what he wants most the outputs to be on hypergrade whats output to the screen like "Your broke, get out of the casino." lol
I figured out the card problem and passed 7/8 of the test but I still am getting the wrong cards on the multiple game on.
to fix the wrong cards I had to remove the CARD c5 = deck[next_index++]
from the beginning were I had them all in a row and the in the player hit section I left that and changed the -- to ++ and the in the dealer section I changed it to CARD c6 = deck[next_index++] along with the values to c6. Also make sure if you used the int init_count = 3 you need to bump that up to 6 to pass hypergrade.
yea the problem with mine seems to be when i go through the while loop the first time it does not remember it has gone through it so it starts back at the value it was at before, instead of going to the next value in the array. i think lol.