|
-
August 14th, 2002, 01:17 PM
#1
Simple question (involving rand() i think)
I'm making a black jack program as an excersize (mostly in structures and such) and i'm having a problem with the deal() method.
the problem seems to be that a) the random number seems to be 13 all the time ('k' is the output twice) and after i enter anything for the cin, it gives me a bus error and quits. any ideas?
(the player struct has a few ints (money, bet) and the name and hand (a 2-element array) for the player.)
this is the code for that method:
void deal(person player)
{
int i;
char askhit[3];
cout<<"You got: ";
for(i = 0; i < 3; i++) {
player.hand[i] = (rand()%13 + 1);
if (player.hand[i] == 11) player.hand[i] = 'j';
if (player.hand[i] == 12) player.hand[i] = 'q';
if (player.hand[i] == 13) player.hand[i] = 'k';
cout<<player.hand[i]<<" ";
}
cout<<endl;
do {
cout<<"Would you like to hit?"<<endl;
cin>>askhit>>endl;
if (askhit[0] == 'y' || askhit[0] == 'Y') hit(player);
} while (askhit[0] == 'y' || askhit[0] == 'Y');
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|