• Advertisement

Archived

This topic is now archived and is closed to further replies.

I need help with my black jack game (c++)

This topic is 5237 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I''m having trouble with dealing the cards correctly. Lemme give you my source first and then I''ll explain my problem.
#include <iostream>
#include <time.h>

int Card[2];
int i = 0;

void SetCards()
{
	int x;
	srand(time(NULL));
	x = rand()%12;
	Card[i] = x;
}

void ShowCards()
{
	std::cout << "Your deck consists of these cards: " << std::endl;
	while(i<3)
	{
		SetCards();
		i++;
	}
	for(int j=0; j<3; j++)
	{
		std::cout << "[" << Card[j] << "] ";
	}
}

int main()
{
	SetCards();
	ShowCards();
	return 0;
}
This is just a mere prototype. I plan to make it OO becuase I like objects and I''ll make it all ''black jacky'' in due time. The problem I''m having is that whenever I compile and run whatever I have here, the first two ''cards'' are the same exact number despite the seed. How can I go about fixing this? I checked my loops and they seemed fine, maybe I should try using references? They do tend to be faster.
R.I.P. Mark Osback Solo Pa Mi Gente VG-Force

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
<pre>
while(i<3)
{
SetCards();
i++;
}
</pre><br>
Your array is going out of range if you do this and could cause some problems set it to while(i<2) or something like that so it doesn''t.

Also this line ''x = rand()%12;'' will generate a number from 0 to 11 you probably want something like ''x = rand()%12+1'' that genereates a number from 1-12.

Share this post


Link to post
Share on other sites

  • Advertisement