title: How do I make a program using 3 overloaded functions (difference in parameters is int, long, float) meanwhile only asking one input entry?
body: <p>I have to write a program where I put in two numbers and the program calculates the average. I want to write my program so that if I input two decimal numbers, the program will call the float function, and if I input two integer numbers it will call the integer function, input two long numbers, it will call long function.</p>
  
  <p>The main problem I am having is choosing the variable type. Because if I use a long type for my variable, but the two numbers input by the user are decimal, then the program calls the long function and the average comes out as a long variable.</p>
  
  <p>Here is what I've got so far:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int average(int, int);
  long average(long, long);
  float average(float, float);
  
  int main()
  {
          //The variables
          //      The problem with them is that if I use
          //      a type, let's say int, but the input
          //      is a float, then it won't work
           x;
           y;
           averag;
  
          std::cout &lt;&lt; "Here is a number: ";
          std::cin &gt;&gt; x;  
          std::cout &lt;&lt; "\nHere is another one: ";
          std::cin &gt;&gt; y;
  
          //The function in call
          averag = average(x, y);
  
          std::cout &lt;&lt; "\n\nHere is the average: ";
          std::cout &lt;&lt; averag;
          return 0;
  }
  
  //The definition of the int function
  int average(int x, int y)
  {
          int x;
          int y;
          int average;
          average = (x + y) / 2;
          return average;
  }
  
  // The definition of the short function
  short average(short x, short y)
  {
          short x;
          short y;
          short average;
          average = (x + y) / 2;
          return average;
  }
  
  // The definition of the float function
  float average(float x, float y)
  {
          float x;
          float y;
          float average;
          average = (x + y) / 2;
          return average;
  }
  
  //I think i'm not grasping the scopes in which I can define a variable
  //and where I must define the parameters within the functions
  </code></pre>
  
  <p>I think that defining the type variables in each function scope is wrong, but how else am i supposed to define the variables!</p>
  
  <p>How to do that ? </p>