This is an endless loop:
cin>>cond;
while(cond=='y'){
urtotal =urtotal+rand()%1;
}
You should have some sort of cond assignment inside the while() loop.
I'm somewhat confused by your code; partly due to the fact that I basically know nothing about the card game you are trying to implement. Also, I fail to see why you use 3*n in loop. Don't you just want to loop once through each player? Here's what I think you should do:
Stack player_stack[number_players];
for (int i=0; i < number_players; i++)
{
player_stack[i].add(Deck.grab_random_card()); // whatever, do your stuff here
// ...
}
You could even have a static member inside Stack that holds the number of players, so you could do something like this:
Stack::number_players = number_players;
Stack player_stack[number_players];
Just a thought.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
I'd consider developing another class to represent a Player and Game. Maybe something conceptually along these lines:
Player
Card hand[5];
int numCards;
int handValue;
int runningTotal;
valueHand();
Game
vector<Player> players;
int numHandsPlayed;
housePays();
determineWinner();
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
I'd consider developing another class to represent a Player and Game. Maybe something conceptually along these lines
Definitely. Of course, it's probably better to declare hand as Stack, because that class has already been implemented, and has such functions as add(), remove(), so you would have more flexibility with that than a static array. Or you could make it a Card vector, in which case you could use the built-in functions for adding and removing cards.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
Hmm... since a Deck is really an advanced Stack, I say you should derive Deck from Stack. It's not really required or anything, but it makes the 2 types more compatible.
Secondly, I think you should add the following member functions to Stack (also to Deck, assuming that Deck is derived from Stack):bool Stack::add_card(Card)
Card Stack::remove_card(int card_number)
Deck shouldn't really be an array, it should be a class that has its own sub-array that holds all the cards. It should then have a member function like Deck::shuffle().
You should have a class named Card, whose only purpose is to hold some static enums so your cards can have names:
Card::Clubs::Jack
Why? Let me show you how easy it would be to manage your card game with this implementation:
// btw, you should add a constructor which automatically fills in the cards
Deck deck;
// same as usual
Stack playercards[number_players];
// shuffling the deck
deck.shuffle();
// adding a card
playercards[0].add_card(Card::Clubs::Jack);
// removing a card
playercards[0].remove_card(3);
// dealing a card from the deck to the first player
playercards[0].add_card( deck.remove_card(51) );
I hope you understand what I'm trying to say. Take special notice of the last line; it uses the both techniques so that the deck gets cards removed, returns the removed card, which is then added to a player's stack. Hopefully this will simplify your code a bit.how can i get back to the old deck from that? If you want to keep a copy of the old deck, simply add a copy constructor, which copies all the data from one object to another. Something like this you might want for Deck:
Deck::Deck(Deck &new_deck) {
// eg.
new_deck.number_cards = number_cards;
// ...
}
Then to make a copy of the deck, all you have to do is like this:
Deck original_deck(deck);
See how easy that was?
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
so sorry... u might be too upset with me! sorry again!
I try my best upon wh u pointed out to me!
You have nothing to worry about. You're certainly not breaking any rules and you're showing effort like it describes in the "homework policy". And it's actually fun helping someone in a programming forum who's actually trying... Hey, we were all newbies once!
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
Hey, we were all newbies once!
No, I would rather put it as "genius in making...." ;)
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
I had the same problem with a VB6 blackjack game, used classes in the end which wasnt very practical.
jbennet
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
>>..how can i get back to the old deck from that? coz each player ll get 3 cards first ,but if they want more I want to go back to old deck ,no duplicates.
Each game has only one deck (or a finite number of decks). If you use a stack to represent the deck then each card will be dealt from the top and when it is dealt it will be removed from the stack so when you go back there can't be any duplicates. It is possible to replicate this functionality by using an array and an index integer to keep track of where you are in the deck. Then, if you feel the top of the deck is the highest integer representing a valid element within the deck, then count backward and if you feel the top of the deck is the lowest integer representing a valid element within the deck then count up. As long as you never reverse course within the scope of any given hand, it works fine.
declare deck
determine number of players
start outer loop
shuffle deck
start inner loop number 1
for each player
deal three cards from top of deck
end loop number 1
start inner loop number 2
for each player
allow each player to take 0, 1, or 2 more cards from the top of the deck
end inner loop number 2
determine winner(s) of hand
end outer loop
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396