title: Subtracting an arbitrary date from the current date C++
body: <p>I'm brand new to C++.  In my Programming I class, I've been given the following assignment as a midterm:</p>
  <blockquote>
  <p>-Calculate how many days you have been alive
  (epoch time from 01/01/1970 stored by seconds)</p>
  <p>-Command Line Args for Birth Year, Birth Month, Birth Day</p>
  </blockquote>
  <p>Now, I've already figured out the function itself for actually subtracting two dates from each other, and I've figured out how to grab the current date and stick it in that function.  The problem I'm having is how to get the user's entered date and send that to the function.</p>
  <p>I've been playing with a &quot;test&quot; piece of code to get this to work, unfortunately when I try to compile this I just get a MOUNTAIN of errors that I don't understand at all, so I'm clearly doing something wrong.</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;ctime&gt;
  
  using namespace std;
  
  struct tm a(int year, int month, int day)
  {
      struct tm birth {0};
      
      cin &gt;&gt; year &gt;&gt; endl;
      cin &gt;&gt; month &gt;&gt; endl;
      cin &gt;&gt; day &gt;&gt; endl;
      
      birth.tm_year = year - 1900;
      birth.tm_mon = month;
      birth.tm_mday = day;
      
      return birth;
  }
  
  int main()
  {
  int year, month, day;
  
  cout &lt;&lt; &quot;Enter a year, month, and day: &quot; &lt;&lt; endl;
  cin &gt;&gt; year &gt;&gt; month &gt;&gt; day &gt;&gt; endl;
  
  tm a(year, month, day);
  time_t x = mktime(&amp;a);
  time_t y = time(0);
  if ( x != (time_t)(-1) &amp;&amp; y != (time_t)(-1) )
  {
      double difference = difftime(y, x) / (60 * 60 * 24);
      cout &lt;&lt; ctime(&amp;x);
      cout &lt;&lt; ctime(&amp;y);
      cout &lt;&lt; &quot;difference = &quot; &lt;&lt; difference &lt;&lt; &quot; days&quot; &lt;&lt; endl;
  }
  return 0;
  }
  </code></pre>
  <p>I've tried googling some of these errors, and the results I'm seeing keep talking about &quot;pointers&quot;.  I have no clue what pointers are, and flipping through our textbook, it looks like something that's about three or four chapters ahead of where we are now.  I tried asking my professor about this the other day, and he just sort of giggled and said something to the effect of &quot;Well yeah, that's the point of the midterm.&quot;  I don't understand if that means I'm supposed to figure out pointers on my own or if I'm not supposed to use them.</p>
  <p>I'm trying to get a year, month, and day from arguments entered by the user at the point of execution and stick them into a struct tm so that my function at the bottom will work.</p>
  <p>EDIT: I figured out that I am trying to use the struct like a function, which is wrong.  I have made the following changes:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;ctime&gt;
  
  using namespace std;
  
  struct tm bday(int year, int month, int day)
  {
       struct tm r {0};
  
       r.tm_year = year - 1900;
       r.tm_mon = month;
       r.tm_mday = day;
  
       return r;
  }
  
  int main()
  {
       int year, month, day;
  
       cout &lt;&lt; &quot;Enter a year, month, and day: &quot; &lt;&lt; endl;
       cin &gt;&gt; year &gt;&gt; endl;
       cin &gt;&gt; month &gt;&gt; endl;
       cin &gt;&gt; day &gt;&gt; endl;
  
       struct tm a = bday(year, month, day);
       time_t x = mktime(&amp;a);
       time_t y = time(0);
       if ( x != (time_t)(-1) &amp;&amp; y != (time_t)(-1) )
       {
            double difference = difftime(y, x) / (60 * 60 * 24);
            cout &lt;&lt; ctime(&amp;x);
            cout &lt;&lt; ctime(&amp;y);
            cout &lt;&lt; &quot;difference = &quot; &lt;&lt; difference &lt;&lt; &quot; days&quot; &lt;&lt; endl;
       }
       return 0;
  }
  </code></pre>
  <p>Now getting the following errors when compiling:</p>
  <blockquote>
  <p>filename.cpp:22:17: error: no match for 'operator&gt;&gt;'</p>
  <p>filename.cpp:23:18: error: no match for 'operator&gt;&gt;'</p>
  <p>filename.cpp:24:16: error: no match for 'operator&gt;&gt;'</p>
  </blockquote>