Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with growing arrays
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
who cares?




PostPosted: Sat Jan 17, 2004 5:54 pm   Post subject: Help with growing arrays

Hey!

I am making a blackjack game for school and I want to have an array that stores all of the values of the cards that the user has drawn. However, i want to make my array dynamic, so that each time a user draws a card, the array expands by 1 to include the value of that card. I have made a test program to help me test this, but i get an error. Can someone PLEASE help me with this? This is the test program:

code:

var counter : int := 1
var test : array 1 .. counter of int
var value : int

loop
    get value
    counter := counter + 1
    test (counter) := value
    put test (counter)
end loop




Thanks a lot! Embarassed
Sponsor
Sponsor
Sponsor
sponsor
shorthair




PostPosted: Sat Jan 17, 2004 6:03 pm   Post subject: (No subject)

if your making blackjack ther is no need for what you want to do , and if you wanted to array to grow you would need both ends to be variables and im not sure how stable it would be ,there are alot more efficant way s to making blak jack , first of all your gonna need 2 arrays , one for the suit and one for the card value , thats a good start
who cares?




PostPosted: Sat Jan 17, 2004 6:08 pm   Post subject: i know that

i have that part figured out, but now i need a way to add all of the points that the user gets from the cards. and storing them in an array seemed pretty efficient to me.
shorthair




PostPosted: Sat Jan 17, 2004 6:12 pm   Post subject: (No subject)

That would be areally bad way to do it , to stopre the users count what you do is take the values of their cards and add them up and IE


code:

playerTotalCount= playerTotalCount + card

That way every time a card is dealt you can add it to the total card count
, this is jsut an easy way to do it , the method i used gets quite complex in some areas its quite unique , if you would like ot see the program its in the turing submissions
who cares?




PostPosted: Sat Jan 17, 2004 6:20 pm   Post subject: THANK YOU !!!

OMG, even my teacher says that's my problem. I think WAY too complicated. What I wanted to do is store all the values of the cards in an array and THEN add them up at the end. WAY more complicated then this. Thanks a lot! Very Happy Very Happy Very Happy
shorthair




PostPosted: Sat Jan 17, 2004 6:22 pm   Post subject: (No subject)

not a problem , this method is very good to find out if the player has gone over 21 aswell because you just say

code:

if playerTotalCount >21 then
put " YOU LOSE"
end if


the same goes for the computer count aswell
AsianSensation




PostPosted: Sat Jan 17, 2004 7:48 pm   Post subject: (No subject)

dynamic arrays:

code:
var name : flexible array 1 .. 1 of string
new name, 5
name (4) := "AsianSensation"
put name (4)


I don't know if they implemented multidimensional flexible arrays in the newer version, but in 4.0.4, you can only have a one dimensional flexible array.
Thuged_Out_G




PostPosted: Sun Jan 18, 2004 12:18 am   Post subject: (No subject)

shorthair wrote:
you would need both ends to be variables and im not sure how stable it would be


im pretty sure thats not correct.

open your help file and look up array....then scroll down to the flexible array(near the bottom)
shorthair




PostPosted: Sun Jan 18, 2004 10:36 am   Post subject: (No subject)

i was incorrect on that but still there is no need for him to use that kind of an array in blackjack , i told hium what he neds to do , he was trying to get rally complex in an easy situation
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: