NO

Author Topic: Working on a array of 5 cards.  (Read 2464 times)

fishin_fl

  • Guest
Working on a array of 5 cards.
« on: February 29, 2016, 03:39:15 AM »
I have been working on my black jack program but I am having troubles.  My menu is working and the 2 cards get chosen, totaled, and printed. It was a temporary setup to try the deal and the random generator. I am supposed to setup an array named playerCards [5] cards max. Also create an integer for playerCardscount and assign it to 0. How do I setup the array to feed in the card values and card suit. I am a beginner at this so my code probably is a mess.  I have put code below.  Also how do you use the code tags?  I clicked on it but it does not do anything. Thanks.

Grincheux

  • Guest
Re: Working on a array of 5 cards.
« Reply #1 on: February 29, 2016, 08:11:01 PM »
Quote
for (int i = 0; i < ((rand() % 200) + 100); i++)

Initialize a variable out of for loop that will generate better code and you will be sure that the number of loop will not change.
Base your random function on time counter because you don't really have random values but repeated values for one period to an other period.

Your program is clear it's a pleasure to read it.

Change (*index)++ by *index++ no need parenthesis

I don't know the rules but explain your problem in a n other way that will easier to help you.

Sorry I had not seen
Quote
srand(time(NULL));   // seed random number generator from time

fishin_fl

  • Guest
Re: Working on a array of 5 cards.
« Reply #2 on: March 02, 2016, 05:02:30 PM »
Thank you for the response. :D  New to writing code.  I was able to work on it some more and found some of my issues.  I am now at the point of adding the computer deal into game and would like to clean up main function so I have as little as possible there.  I do think I have an issue with the reset totals once and a while but all is looking better.  This is the following to-do list. Plus making the console look good.
a. Make computer side     
b. Deal card to player     //print console message
c. Deal card to computer     //print console message
d. Deal card to player     //print console message
e. Deal card to computer (hidden)   //print x instead of # and suit
f. Display results     //Print cards and show the totaled results
g. Ask if player would like to hit on cards until bust or 5 cards in total
     (5 cards maximum in total, 2 originals + 3 possible hits)
h. Show totals at every hit
I. Have computer determine if it would hit or stay     //house hits at 16 and stays at 17
     (5 cards maximum in total, 2 originals + 3 possible hits)
j. Show totals on every computer hit
k. Determine who won or lost     /Print console message
l. Allow player to play again     //Loop was setup in previous code
And finally
Add a variable that gives the player a starting amount of chips(Cash)
add the functionality to bet before each hand dealt.
After each hand completed, update the chip count appropriately based on the bet and results of game //
(bets pays 1:1, so a $50 bet wins $100 ( $100-50 (original bet)=amountwon0






fishin_fl

  • Guest
Re: Working on a array of 5 cards.
« Reply #3 on: March 06, 2016, 03:10:18 PM »
I am trying to correct the resetting variables for this game.  Some times it works and sometimes it does not.  Any ideas.

When doing the print out for the following: Should I put this all in a function or at the beginning.  When I print the second card for player it shifts up between player card and computer card.  Which I know is wrong.

b. Deal card to player     //print console message
c. Deal card to computer     //print console message
d. Deal card to player     //print console message
e. Deal card to computer (hidden)  //print x instead of # and suit
f. Display results     //Print cards and show the totaled results




Thanks
« Last Edit: March 06, 2016, 03:24:56 PM by fishin_fl »