title: cin >> function template arg of unknown type
body: <p>I have a function template and main as follows:</p>
  
  <pre><code> template &lt;class type &gt; type* calculate(type inputVal) {
         type val;
         static int counter = 0;
         static type sum = inputVal;
         static type average = inputVal;
         static type* address = &amp;sum
  
         do {
            cout &lt;&lt; "Enter value: ";
            cin &gt;&gt; val;
            counter++;
            sum += val;
            average = sum / counter;
         } while (!cin.eof());
        return address;
   }
  
  void main() {
        int num;
        cout &lt;&lt; "Enter Value: ";
        cin &gt;&gt; num;
        int *ptr = calculate(num);
        cout &lt;&lt; "SUM: " &lt;&lt; *ptr &lt;&lt; " AVG: " &lt;&lt; *(ptr+1);
   }
  </code></pre>
  
  <p>My problem is that this should work with different input types instead of just int, so if a user first enters a float it'll treat everything as that type, as wells as if the user enters a char.</p>
  
  <p>Also the template function cannot print the end values.</p>