title: Too Many Arguments in C++
body: <p>I am facing difficulties in my C++ code. I am a beginner. Like, only with very basic knowledge of C++. So, I really can't figure a way to do this. I thought of making an RPG game using C++ commands and am close to finishing it. But somehow, I couldn't make a constant health for the hero. Taking a look at the code,</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;ctime&gt;
  
  
  
  using namespace std;
  
  
  class player
  {   public:
      int health = 100;
  };
  
  int battle();
  void death();
  
  int main()
  {
     int abc;
     player hero;
     hero.health = abc;
     int a;
     int replay = 1;
     cout &lt;&lt; "You have 100 Hp. \n";
     while (replay == 1)
  {
  
  srand(time(0));
  cout &lt;&lt; "\n Press 1 to move forward; 2 To stay. \n";
  cin &gt;&gt; a;
      if (a == 2)
      {
          if (rand() % 4 + 1 != 1)
          {
              cout &lt;&lt; "You stay at your place. \n";
          }
          else
          {
              cout &lt;&lt; "Enemy Attacks! (20 Hp) \n";
              //battle(hero.health);
              //cout &lt;&lt; "\n Press 1 to continue. \n";
              cout &lt;&lt; "\n Do you want to play again? Press 1 to replay and 0 to quit.\n";
              cin &gt;&gt; replay;
          }
      }
      else if (a == 1)
      {
          if (rand() % 2 + 1 != 1)
          {
              cout &lt;&lt; "You moved forward. No one around. \n";
          }
          else
          {
              cout &lt;&lt; "You move forward. Enemy attacks! (20 Hp) \n";
              battle(abc);
              cout &lt;&lt; "\n Do you want to play again? Press 1 to replay and 0 to quit.\n";
              cin &gt;&gt; replay;
          }
      }
      else
      {
          cout &lt;&lt; "Sorry. Please enter a valid move. \n";
      }
  
  }
  
  return 0;
  }
  
  int battle(int x)
  {
     player enemy;
     enemy.health = 20;
     player hero;
     int y;
  
  
  while (enemy.health &gt;= 0)
  {
  int eattack = rand() % 15 + 7;
  int attack = rand() % 10 + 1;
  int escape = rand() % 4 + 1;
  cout &lt;&lt; "\n Press 1 to attack. 2 to flee \n";
  cin &gt;&gt; y;
  if (y == 2)
      {
        if (escape != 1)
        {
          cout &lt;&lt; "Can't escape! \n";
          cout &lt;&lt; "Enemy attacked! Dealing a damage of: " &lt;&lt; eattack &lt;&lt; " Hp. \n";
          hero.health = hero.health - eattack;
          cout &lt;&lt; "Your Hp is: " &lt;&lt; hero.health;
        }
        else
        {
          goto Aftermath;
        }
  
      }
  else if (y != 1)
      {
          cout &lt;&lt; "Sorry. Please enter a valid response. \n";
      }
  else
      {
          cout &lt;&lt; "You attack the enemy. \n";
          cout &lt;&lt; "You deal a damage of: " &lt;&lt; attack;
          enemy.health = enemy.health - attack;
          if (enemy.health &gt;= 0)
          {
              cout &lt;&lt; "\n Enemy attacks you, dealing: " &lt;&lt; eattack &lt;&lt; " Hp damage.";
              hero.health = hero.health - eattack;
              cout &lt;&lt; "\n You have: " &lt;&lt; hero.health &lt;&lt; " Hp left.";
          }
      }
  
  if ((hero.health &lt;= 0) || (hero.health == 0))
      {
          death();
          enemy.health = -1;
      }
  }
  
  if (hero.health &gt; 0)
      {
          cout &lt;&lt; "\n Enemy fainted!";
          //cout &lt;&lt; "You found Hp Potion! Your Hp was refilled.";
      }
  
     Aftermath:
        if ((hero.health &gt; 0) &amp;&amp; (enemy.health &gt; 0))
         {
            cout &lt;&lt; "Escaped Successfully! \n";
         }
  
       return x;
  
    }
   void death()
      {
        cout &lt;&lt; "You died!";
      }
  </code></pre>
  
  <p>As you see, I have called for <code>battle(abc)</code> and <code>battle(hero.health)</code> [which I have commented for now] but the problem is, it says "Too many arguments to function <code>int battle()</code>. Previously, I simply avoided parameters and created object "hero" in the battle method itself. But every time you get through a battle sequence, it comes back and declares it again, thus making its health refill. [Look at <code>if (hero.health &gt; 0)</code> ]</p>
  
  <p>I really don't know about global variables and all that. I just want to know if there is a workaround or a way to solve this parameter problem. Any other suggestions to have health as a 'constant' and not declared every time is also warmly accepted. Thank you so much!</p>
  
  <p>P.S. Suggestions for shortening the code also accepted but please, I am a beginner. So advanced strategies are beyond my skills right now. I take time to grasp concepts.</p>