*Code Deleted For Protection*
Printable View
*Code Deleted For Protection*
Are player and computer global variables?
Yes both are global.
here is a list of all my global vars
Code:
int CStay; //COMPUTER STAYS
int PStay; //PLAYER STAYS
int Played; //TOTAL GAMES PLAYED
int Player; //PLAYER TOTAL CARDS
int Computer; //COMPUTER TOTAL CARDS
int Won = 0; //GAMES WON
int Lost = 0; //GAMES LOST
int Tie = 0; //GAMES TIED
int PAgain; //PLAY AGAIN INPUT FROM PLAYER
int Again = 1; //PLAY AGAIN
int Cont; //CONTINUE?
It looks like you have a few too many calls to other functions in main(). And also, you don't need the "do" statements at all. The best thing is to have a simple WHILE loop control whether or not your program is running:
while (Exit == false)
....for example. If you can contain everything in a nice while or for loop, you can avoid writing extra lines where you make calls to the same functions again and again. Also, the use of global variables is generally frowned on because ANY function can alter them, which defeats the purpose of encapsulating data and hiding it from functions that do not need to be tampering with it.
im pretty new to functions, this was an exercise from my book, only it wasnt in as great detail as im making it, i added many features to the game.
ive pin pointed the problem to be (like i think you said) my int main function, where i call all the other functions. tomorrow, im going to write a new int main function on some paper, and then try that out.
try a structure closer to this for starters:I'm not sure if that's how you intended your logic, but I'm pretty sure that's how it is... then again I did get kinda lost in your code a few times...Code:int main(void)
{
cout<<"WELCOME TO BLACK JACK CREATED BY NATHAN KRYGIER.\n\n";
cout<<"PRESS ENTER TO BEGIN THE GAME\n\n";
getch(); //WAIT FOR USER TO PRESS RETURN
system("cls"); //CLEAR SCREEN
do
{
NewGame(); //since it's a new game, clear card value
FirstDeal(); //CALL FIRSTDEAL FUNCTION
do{
HitStay(); //HIT OR STAY?
Check(); //CHECK FOR A WINNER
AI(); //AI's turn (presumably)
Check(); //check for a winner
}while(Cont == 1);
Update();
PLAgain();
}while(Again == 1);
Stats(); //SHOW STATS FOR THE PLAYERS SESSON
cout<<"\n\nThank you for playing Black Jack";
getch(); //WAIT FOR USER TO PRESS RETURN
return(0); //Doesn't confirm anything - only a return value that can be used
//to confirm something
}