• Advertisement

Archived

This topic is now archived and is closed to further replies.

Game exit problem

This topic is 5219 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I'm having a wierd problem with exiting my little Black Jack game... Everytime I lose or win it asks me if I want to continue, well, it doesn't really ask me but it should. Instead, it flashes by and continues my game loop. If you look at the history it says I put down a nine (to continue you have to press 0 to exit and any other number to continue). And, when I lose the lose notification works fine, but when I win, it says I won AND lost at the same time! Here's the code: #include <iostream> #include <cstdlib> #include <stdlib.h> #include <time.h> using namespace std; int main() { // Game functions char pName [100]; int p1Card; int p2Card; int p1Card2; int p2Card2; int p1Hitme; int p2Hitme; int stateHitme; unsigned long n; cout << "==========================================\n"; cout << " Black Jack AK version >> By Alex Klos\n"; cout << "========================================\n\n"; cout << " Get 21 or closest to it to win.\n\n"; cout << " So, what's your name? "; cin.getline (pName,100); cout << "\n\n"; do { // Creates random number (1-11) srand((unsigned)time( NULL )); p1Card = (rand() % 10) + 1; ((unsigned)time( NULL )); p2Card = (rand() % 10) + 1; ((unsigned)time( NULL )); p1Card2 = (rand() % 10) + 1; ((unsigned)time( NULL )); p2Card2 = (rand() % 10) + 1; cout << " Ok, " << pName << " your first card is: " << p1Card; cout << "\n\n The computers first card is: " << p2Card << "\n\n"; system("PAUSE"); cout << "\n\n"; cout << "\n\n And now, your second card is: " << p1Card2; cout << "\n\n And the computers second card is: " << p2Card2; cout << "\n\n"; system("PAUSE"); cout << "\n\n"; cout << "Your cards add up to: " << p1Card + p1Card2 << "\n"; cout << "The computers cards add up to: " << p2Card + p2Card2 << "\n\n"; system("PAUSE"); cout << "\n\n"; cout << "Do you want another card? (0 = No, 1 = Yes) "; cin >> stateHitme; if(stateHitme == 1); { ((unsigned)time( NULL )); p1Hitme = (rand() % 10) + 1; cout << "With the third card your cards add up to: " << p1Card + p1Card2 + p1Hitme; cout << "\n\n"; system("PAUSE"); } else if(stateHitme != 1); { cout << "You chose not to get another card."; cout << "\n\n"; system("PAUSE"); } if(p2Card + p2Card2 <= 16); { ((unsigned)time( NULL )); p2Hitme = (rand() % 10) + 1; cout << "The computer chose to get another card.\n"; cout << "With the third card the computers cards add up to: " << p2Card + p2Card2 + p2Hitme; cout << "\n\n"; system("PAUSE"); } if(p2Card + p2Card2 + p2Hitme == p1Card + p1Card2 + p1Hitme) { cout << "It's a tie! Try again!\n\n"; system("PAUSE"); cout << "\n\n"; } else if(p1Card + p1Card2 + p1Hitme > p2Card + p2Card2 + p2Hitme, p1Card + p1Card2 + p1Hitme < 22) { cout << "Good job! You win!\n\n"; system("PAUSE"); cout << "\n\n"; } else if(p2Card + p2Card2 + p2Hitme < p1Card + p1Card2 + p1Hitme, p2Card + p2Card2 + p2Hitme > 22); { cout << "Sorry, you lost!\n\n"; system("PAUSE"); cout << "\n\n"; } cout << "Do you want to try again? (0 to end, any other number to continue) "; cin >> n; } while(n != 0); system("PAUSE"); return 0; } (How do I turn my source code into editable version?) [edited by - WaterMelon34 on October 5, 2003 9:39:28 PM]

Share this post


Link to post
Share on other sites
Advertisement
Dunno what u mean by that last question, but u might try putting it between a
 and 
tag. Or maybe it''s
 and [/CODE]...   

Share this post


Link to post
Share on other sites
Some of your if statements are followed by semi colons.
by doing that you end the if statment and the following code in brackets is run whether or not the statment was true or false.

Share this post


Link to post
Share on other sites

  • Advertisement