title: Calculating the distance between two random points in a C++ Battleship game
body: <p>So, my problem is how to calculate the distance between the two random points (x,y) so i can use the abs method (as i was starting to do in the Function bool CheckColpo) and tell the player if his shot was actually in range of the enemy ship's position. How can you calculate the distance between two things that'll be random? How should i approach this? i know that i need to use the abs function AFTER i found the distance between the two points. I had a friend that was trying to explain it to me, but i guess i'm too thickheaded. I'm new to programming and C++ is the first language i'm learning, i hope someone can point out the way.</p>
  
  <p>Here's my code : </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;ctime&gt;
  #include &lt;cstdlib&gt;
  #include &lt;string&gt;
  using namespace std;
  
  const int RIGHE = 10;
  const int COLONNE = 10;
  
  const char NAVE = 'N';
  const char MARE = '~';
  int x = -1;
  int y = -1;
  int choice1;
  int choice2;
  
  char board[RIGHE][COLONNE];
  
  //Funzione per stampare la griglia 10x10 con il For//
  void StampaGriglia() {
      cout &lt;&lt; "Here's the board : \n";
  
      for (int i = 0; i &lt; RIGHE; ++i)
      {
          for (int k = 0; k &lt; COLONNE; ++k)
          {
              cout &lt;&lt; board[i][k];
          }
          cout &lt;&lt; endl;
      }
  }
  
  void TurnoPlayer() {
      do {
          cout &lt;&lt; "Enter the ship to sink :";
          cin &gt;&gt; choice1;
          cout &lt;&lt; endl;
          cout &lt;&lt; "Enter your second ship :";
          cin &gt;&gt; choice2;
          if (choice1 == x &amp;&amp; choice2 == y)     // IN CASO AVESSI VOLUTO FARE CON IL CHAR NAVE : board[choice1][choice2] == nave;//
          {
              cout &lt;&lt; "Boom, you sank it! ";
          }
          else
          {
              cout &lt;&lt; "Retry! ";
          }
          cout &lt;&lt; endl;
  
  
      } while (choice1 &lt; 0 || choice1 &gt;  RIGHE || choice2 &lt; 0 || choice2 &gt; COLONNE);
  }
  
  
  bool PlayAgain(string question)
  {
      char again;
  
      cout &lt;&lt; question;
      cin &gt;&gt; again;
  
      return again == 'y';
  }
  
  bool CheckColpo() {
      x = abs
  }
  
  
  
  int main()
  {
      do {
          //INSERISCI IN TUTTE LE CELLE UN VALORE BASE (MARE)//
          for (int i = 0; i &lt; RIGHE; ++i)
          {
              for (int k = 0; k &lt; COLONNE; ++k)
              {
                  board[i][k] = MARE;
              }
          }
  
          srand(static_cast&lt;unsigned int&gt;(time(0)));
          x = rand() % 10;
          y = rand() % 10;
  
          board[x][y] = NAVE;
  
          cout &lt;&lt; "x :" &lt;&lt; x &lt;&lt; "y: " &lt;&lt; y;
  
          do
          {
  
              StampaGriglia();
              TurnoPlayer();
  
          } while (choice1 != x || choice2 != y);
      } while (PlayAgain("Vuoi Giocare Ancora? (y/n)"));
  
      return 0;
  }
  </code></pre>
  
  <p>Thanks a lot ,
  and  if i made this post in a wrong way i'll take action to correct it right away.</p>