title: Using functions in C++ (void, double, int)
body: <p>I am slowly trying to learn c++ on my own and got stuck using functions. I did find a way to get past the initial problem but I have no idea why I couldn't do it the way I first intended to. Here's the working program. </p>
  
  <pre><code>// ex 6, ch 2
  #include &lt;iostream&gt; 
  using namespace std; 
  
  void time(int, int);
  int main() 
  {
  int h, m; 
  cout &lt;&lt; "Enter the number of hours: "; 
  cin &gt;&gt; h; 
  cout &lt;&lt; endl; 
  cout &lt;&lt; "Enter the number of minutes: "; 
  cin &gt;&gt; m; 
  cout &lt;&lt; endl; 
  time(h, m); 
  
  cin.get();
  cin.get();
  return 0; 
  } 
  
  void time(int hr, int mn)
  {
   cout &lt;&lt; "The time is " &lt;&lt; hr &lt;&lt; ":" &lt;&lt; mn;  
  }
  </code></pre>
  
  <p>And here is how I would like to do it. </p>
  
  <pre><code>// ex 6, ch 2
  #include &lt;iostream&gt; 
  using namespace std; 
  
  void time(int, int);
  int main() 
  {
  int h, m; 
  cout &lt;&lt; "Enter the number of hours: "; 
  cin &gt;&gt; h; 
  cout &lt;&lt; endl; 
  cout &lt;&lt; "Enter the number of minutes: "; 
  cin &gt;&gt; m; 
  cout &lt;&lt; endl; 
  cout &lt;&lt; "The time is " &lt;&lt; time(h, m); 
  
  cin.get();
  cin.get();
  return 0; 
  } 
  
  void time(int hr, int mn)
  {
   cout &lt;&lt; hr &lt;&lt; ":" &lt;&lt; mn;  
  }
  </code></pre>
  
  <p>In my head both of them would return the same thing but my compiler thinks otherwise (and I would like to know why). </p>
  
  <p>Edit: It seems to work like this for some odd reason. </p>
  
  <pre><code>cout &lt;&lt; "The time is "; 
  time(h, m); 
  </code></pre>
  
  <p>If nothing more, it just made me more confused. </p>