*Code Deleted For Protection*
*Code Deleted For Protection*
Last edited by Frantic-; 02-03-2005 at 09:04 PM.
Are player and computer global variables?
Stupid things pop singers say
"I get to go to lots of overseas places, like Canada."
- Britney Spears
"I love what you've done with the place!"
-Jessica Simpson upon meeting the Secretary of Interior during tour of the White House
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 }
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT