4 Replies - 1000 Views - Last Post: 22 July 2018 - 02:15 AM Rate Topic: -----

#1 pbivens85   User is offline

  • D.I.C Addict

Reputation: -13
  • View blog
  • Posts: 507
  • Joined: 22-October 13

blackjack

Posted 20 July 2018 - 02:49 PM

void dealer::deal_one()
{
	srand(time(NULL));
	int num_three = rand() % 13 + 2;
	cout << num_three << endl;
}

void dealer::deal_two()
{
	int num_four = rand() % 13 + 2;
	cout << num_four << endl;
}

void player::play_one()
{
	srand(time(NULL));
	int num_one = rand() % 13 + 2;
	switch (num_one)
	{
	case J:
		cout << "J" << endl;
		break;
	case Q:
		cout << "Q" << endl;
		break;
	case K:
		cout << "K" << endl;
		break;
	case A:
		cout << "A" << endl;
		break;
	default:
		cout << num_one << endl;
		break;
	}
}

void player::play_two()
{
	int num_two = rand() % 13 + 2;
	switch (num_two)
	{
	case J:
		cout << "J" << endl;
		break;
	case Q:
		cout << "Q" << endl;
		break;
	case K:
		cout << "K" << endl;
		break;
	case A:
		cout << "A" << endl;
		break;
	default:
		cout << num_two << endl;
		break;
	}
}

int main()
{
	player play;
	dealer deal;
	int bet = 0;
	cout << "Welcome to Black Jack" << endl;
	cout << "Dealer: " << endl;
	deal.deal_one();
	deal.deal_two();
	cout << "Player: " << endl;
	play.play_one();
	play.play_two();
	system("pause");
	return 0;
}


well I able to get this game to output the dealer and player hands but they are the same, I want it to be able to output the hands but they are different. I believe my problem is in the usage of srand(time(NULL)).

Is This A Good Question/Topic? 0
  • +

Replies To: blackjack

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14776
  • View blog
  • Posts: 59,069
  • Joined: 12-June 08

Re: blackjack

Posted 20 July 2018 - 03:26 PM

You should have one class of type card.
One class of type deck that contains a collection of card objects.
Fill a deck object.
Shuffle how ever you feel like doing.
Deal one card by removing it from the deck and adding the card object to a player's deck object.
Was This Post Helpful? 0
  • +
  • -

#3 pbivens85   User is offline

  • D.I.C Addict

Reputation: -13
  • View blog
  • Posts: 507
  • Joined: 22-October 13

Re: blackjack

Posted 21 July 2018 - 04:07 PM

well modi123 I am trying to follow your advice.
#include <iostream>
#include <time.h>

using namespace std;

enum suit { S, H, D, C };
enum face { J = 11, Q, K, A };

class card
{
private:

public:

};

class deck
{
private:

public:

};

int main()
{



	system("pause");
	return 0;
}

here is my skeleton code.

This post has been edited by pbivens85: 21 July 2018 - 04:08 PM

Was This Post Helpful? 0
  • +
  • -

#4 ndc85430   User is online

  • I think you'll find it's "Dr"
  • member icon

Reputation: 957
  • Posts: 3,791
  • Joined: 13-June 14

Re: blackjack

Posted 21 July 2018 - 08:58 PM

There's practically nothing there! Are you trolling or are you seriously asking us to do the work for you? You've been here long enough to know how it works...
Was This Post Helpful? 1
  • +
  • -

#5 victorman   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 19
  • Joined: 03-July 18

Re: blackjack

Posted 22 July 2018 - 02:15 AM

Last i needed to do this here's what I did.

  • Create an array of the size of the deck of cards. its initial values will be that of a sorted deck of cards. deck[i] = i for all i.
  • get a random number between 0 and 51 inclusive and take that value from the deck and put it in your player's hand.
  • to signal that a card has been taken, assign that spot in the deck to a non-card value. All of your cards are positive numbers so assign it a negative number.
  • now if the random card you try to deal is negative, iterate through the deck to get the next valid card value, and if you reach the end go back to the 0th element.
  • repeat only as needed

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1