#include <iostream>
using namespace::std;
#include "deck1.h"
#include "hand1.h"
int main()
{
Deck d; // instantiate object d of class Deck
Hand player, dealer; // instantiate player and dealer objects of class Hand
int choice; // player inputs a selection
int card = d.deal(); // gives card value of dealt card
cout << "(S)tand, (H)it, (Q)uit: ";
cin >> choice;
while (choice != 'Q' && choice != 'q'){
switch (choice){
case '?':
d.shuffle();
d.print();
cout << endl;
break;
case 'H':
case 'h':
cout << "You draw a " << card << endl;
player.addCard(card);
cout << "Dealer shows a " << card << endl;
dealer.addCard(card);
player.print();
break;
case 'S':
case 's':
cout << "Dealer draws a " << card << endl;
dealer.addCard(card);
dealer.print();
break;
default:
break;
} // end switch
} // end while
return 0;
}
The while is causing an infinite loop. And the switch statement isn't working right. It just prints out "(S)tand, (H)it: H and then goes to the next line without going into the switch statement. Without the while and switch statements, all those commands print out as they're supposed to, but I need the ability to keep filling the two hands. Anyone see what I'm doing wrong?
Lyinar Ka`Bael, Piney Fresh Druidess - Luclin
nm I remembered what the switch statement is! Delidgamond fucked around with this message on 02-11-2007 at 01:13 AM.
I only see one spot where you're reading a new value for 'choice' and it's outside the loop.
Lyinar Ka`Bael, Piney Fresh Druidess - Luclin
code:
def foo():
print "C++? lol"
Yes, yes it does. Use it when posting code.
quote:
Cherveny postedAlso, why do you declare choice to be an int, when you are using it for character values? Shouldn't you delcare it to be a char?
I sincerely doubt that your compiler is dumb enough to leave trash in the top three bytes of an int.
Lyinar Ka`Bael, Piney Fresh Druidess - Luclin
quote:
Lyinar Ka`Bael postedWhat's the C++ version of C's fpurge? Think that might help the infinite loop I'm still getting. Although my program's changed quite a bit from that. That was just trying to get things working and test the class calls.
Uh, i doubt you're getting an infinite loop because of stream buffering.
fpurge is pretty sloppy anyway, in my opinion.
<initialize>
<Initial Question>
<Loop Begin>
<Process input>
<Read new input>
<Loop End>
or
<initialize>
<Loop Begin>
<Read new input>
<Process input>
<Loop End>
We figured it out.
I could use some advice, though. I need to figure out winnings for each hand and keep track of those for an ever-changing bankroll. What's the best way to set that up? Lyinar Ka`Bael fucked around with this message on 02-12-2007 at 11:32 PM.
Lyinar Ka`Bael, Piney Fresh Druidess - Luclin
[edit]looking at it, you'd probably want it to be another class, and you just call all the functions for handling the bankroll, make a function that's called everytime you start a hand that asks you about wagering, after the player handles his wagering though, it's gonna be a little messy. You'll have to determine how the computer will figure out it's wager. I'm completely unseasoned on gambling so I don't know if in BJ you bet after the deal or before the deal. Either or you'll have you figure that out.[/edit] Doomjudge fucked around with this message on 02-14-2007 at 11:46 PM.
quote:
Naimah had this to say about Optimus Prime:
I'd personally make a player class that contains both their hand and their bank/wager as child classes. This way the program can more easily support any number of players.
Yeah, that'd be the best bet actually.
Lyinar Ka`Bael, Piney Fresh Druidess - Luclin
You're not even a man ffs.