trent
03-16-05, 11:31 AM
Hi, I am in a beginning c++ class and I am trying to figure out some array issues that are bugging the crap out of me.
I have to write a program that simulates the card game war. I will read in a .txt file with all the cards in it (all represented as integers 2-14) and then distribute them to two players and then simulate the game. nothing is printed to screen except how many hands were used and who won.
My problem is this: I have been able to bring in the .txt file and assign each player his cards (26 to each). I created a function to simulate the actual game part of this and I am can not get the array to work right. I am supposed to compare each player's card in order and then whichever player wins I put the winner's card along with the loser's card at the end of the array. Is there a way to declare the array dynamically and just update the size of it as I go? Then I can just check for a !=array.eof or something like that to figure out who won and i can just have a regular counter to figure out how many hands went into it right?
Right now i have a p1[26] and p2[26]. Can i just declare them as arrays and update their size as needed? I have visited several c++ help sites, tutorials, and even spoken to a few friends but haven't been able to find anything that has helped.
Thanks for your time and I appreciate any help that you can offer.
Trent
I have to write a program that simulates the card game war. I will read in a .txt file with all the cards in it (all represented as integers 2-14) and then distribute them to two players and then simulate the game. nothing is printed to screen except how many hands were used and who won.
My problem is this: I have been able to bring in the .txt file and assign each player his cards (26 to each). I created a function to simulate the actual game part of this and I am can not get the array to work right. I am supposed to compare each player's card in order and then whichever player wins I put the winner's card along with the loser's card at the end of the array. Is there a way to declare the array dynamically and just update the size of it as I go? Then I can just check for a !=array.eof or something like that to figure out who won and i can just have a regular counter to figure out how many hands went into it right?
Right now i have a p1[26] and p2[26]. Can i just declare them as arrays and update their size as needed? I have visited several c++ help sites, tutorials, and even spoken to a few friends but haven't been able to find anything that has helped.
Thanks for your time and I appreciate any help that you can offer.
Trent