   Blackjack (a C++ issue)
  I am trying to make a simple blackjack game just for some practice.  I have a simple issue with my game so far and I could use some help.  In my current code I need the first to set up a randomizing variable (currently all I have is that you input a number and it moves on, as if you drew that).  But even more importantly I can't seem to remember how to get my program to loop back around again.  If you guys seen any other problems with my game so far please let me know:#include <iostream>using namespace std; int main(){    int score=0;    int current=0;    int add=0;    int close;   cout << "BLACKJACK \n";   if (current < 21)    {    cin >> add;    current = current + add;    cout << "your current number:" << current;    cout << "\n";   if (current > 21)    {  cout << "You Lose";    }    else   if (current = 21)    {  cout << "You Win";  score = score + 1;    }    }//terminate the program    cin >> close;    cin.get();}   
  To have your game loop back again, use just that a loop. Any loop would work, but in this case I'd probably use a do { } while(); loop. Make the condition of the while false if the user wants to exit.For random numbers, use the rand() function. See here: http://www.cplusplus.com/reference/clibrary/cstdlib/rand.htmlThat page also has a number guessing example that allows the user to replay the game just like you want.   ;  just put a simple do while loop around the code. Your game is very very simple obviously. A blackjack game i dealt with in c++ class had about 8 classes in it.this should work.#include <iostream>using namespace std;int main(){string question;do{int score=0;int current=0;int add=0;int close;bool keepPlaying = true;cout << "BLACKJACK \n";if (current < 21){cin >> add;current = current + add;cout << "your current number:" << current;cout << "\n";if (current > 21){cout << "You Lose";}else if (current = 21){cout << "You Win";score = score + 1;}}cout << "Play again? y/n" << endl;cin >> question;}} while(question == "y" or question == "Y");//terminate the programcin >> close;cin.get();;  Don't use string for this. Use a single char. It's also better for a beginner to avoid using those C++ classes like string and use character arrays instead for strings. They will learn a lot more and become better programmers by doing that. A long time ago, that's what my programming teachers said and I now understand why.Plus, it's faster to do if( ch == 'y' ) assuming ch is a char than it is doing if( ch == "y" ) if ch is of the string class type.   ;Quote:Original post by SirKnightDon't use string for this. Use a single char. It's also better for a beginner to avoid using those C++ classes like string and use character arrays instead for strings. They will learn a lot more and become better programmers by doing that. A long time ago, that's what my programming teachers said and I now understand why.Plus, it's faster to do if( ch == 'y' ) assuming ch is a char than it is doing if( ch == "y" ) if ch is of the string class type.I have to disagree. The string class is great. I never programmed in C, but I know about c-strings, or char[]. A string works fine for this and obviously ouputing information in more complex terms later.;Quote:Original post by SirKnightDon't use string for this. Use a single char. It's also better for a beginner to avoid using those C++ classes like string and use character arrays instead for strings. They will learn a lot more and become better programmers by doing that. A long time ago, that's what my programming teachers said and I now understand why.Plus, it's faster to do if( ch == 'y' ) assuming ch is a char than it is doing if( ch == "y" ) if ch is of the string class type.I have to disagree. The string class is great. I never programmed in C, but I know about c-strings, or char[]. A string works fine for this and obviously outputing information in more complex terms later.;  I am a little confused.  First before I ask about a new game I need to ask then if they want to hit or not (a bit lost at this step).  Then I can worry about starting a entirely new game.  Guys I was really hoping for a simple answer, this is only meant to be a simple warmup example.  I would rather not use strings or classes unless they are needed.   ;  Blackjack is a complicated game. There card face values, suits(or atleast a way to keep track of 4 types of each card). Wether a card is face up or down. Many others. The book beginning c++ game programming has a blackjack source code in it. I would send you my altered version as I did a couple exercises, and split the classes into separate files. But I think that would break the laws of utilizing the source code.   ;  What I have in mind is very simple.  All I want to do is make it so that you start with a random number (ten or less), then it simply asks "Hit?".  If you say yes it adds a random number (ten or less) onto the current one.  It keeps doing this till you say no, the number equals 21, or the number is over 21.  Then it tells you how many wins and losses you have, then restarts current number.  Last time I check that isn't that difficult.  I don't plan on doing any GUI's or anything, just a short and sweet little mini game.   ;  Ok I kindof got this going for me here.  I have a working loop but whenever you add the first number it automaticly = 21 and it says you win.  Then all the inputs work fine.  Here is what I have so far:#include <iostream>using namespace std;int wins=0;int loses=0int current=0;int add=0;int close;int running=0;int main(){    cout << "BLACKJACK \n";    for(;;)    {    cin >> add;    current = current + add;    add=0;    cout << "your current number:" << current;    cout << "\n";    if (current > 21)    {  cout << "\n You Lose";  loses = loses + 1    }    else if (current = 21)    {  cout << "\n You Win";  wins = wins + 1;    }}//terminate the programcin >> close;cin.get();}