title: finding the number of seconds since it last struck 12 when user inputs an hour, minute, and seconds (c++)
body: <p>I'm trying to write a function that takes the time as three integer arguments (hours, minutes and seconds) and returns the number of seconds since the last time the clock “struck 12.” Use this function to calculate the amount of time in seconds between two times, both of which are within one 12-hour cycle of the clock. </p>
  
  <p>This is the code I have and every time I compile it, it won't stop running. </p>
  
  <pre><code>#include &lt;iostream&gt;
  using std::cout;
  using std::cin;
  int passedSeconds(int, int, int);
  int difference(int, int, int);
  
  int main()
  {
      int hour1, minute1, second1;
      int hour2, minute2, second2;
  
      cout &lt;&lt; "1. Enter hours, minutes and seconds (range 00:00:00 - 23:59:59): ";
      cin &gt;&gt; hour1 &gt;&gt; minute1 &gt;&gt; second1;
  
      while(hour1 &gt; 23 || minute1 &gt; 59 || second1 &gt; 59)
      {
          if(hour1 &lt; 23)
              cout &lt;&lt; "\nEnter correct hours value!";
          if(minute1 &lt; 59)
               cout &lt;&lt; "\nEnter correct minutes value!";
          if(second1 &lt; 59)
               cout &lt;&lt; "\nEnter correct seconds value!";
  
          cout &lt;&lt; "\n1. Enter hours, minutes and seconds: ";
          cin &gt;&gt; hour1 &gt;&gt; minute1 &gt;&gt; second1;
      }
      cout &lt;&lt; "Passed seconds from last 12 (am or pm): " &lt;&lt; passedSeconds(hour1, minute1,second1);
  
      cout &lt;&lt; "\n2. Enter hours, minutes and seconds (range 00:00:00 - 23:59:59): ";
      cin &gt;&gt; hour2 &gt;&gt; minute2 &gt;&gt; second2;
  
      while(hour2 &gt; 23 || minute2 &gt; 59 || second2 &gt; 59)
      {
          if(hour2 &lt; 23)
              cout &lt;&lt; "\nEnter correct hours value!";
          if(minute2 &lt; 59)
              cout &lt;&lt; "\nEnter correct minutes value!";
          if(second2 &lt; 59)
              cout &lt;&lt; "\nEnter correct seconds value!";
  
          cout &lt;&lt; "\n2. Enter hours, minutes and seconds: ";
          cin &gt;&gt; hour2 &gt;&gt; minute2 &gt;&gt; second2;
      }
      cout &lt;&lt; "\nDifference between two times is "
           &lt;&lt; difference(hour2, minute2, second2) - difference(hour1, minute1, second1) 
           &lt;&lt; " seconds.";
  
      return 0;
  }
  
  int passedSeconds(int hour, int minute, int second)
  {
      if(hour &gt;= 12)
          hour -= 12;
  
      return hour * 60 * 60 + minute * 60 + second;
  }
  
  int difference(int hour, int minute, int second)
  {
      return hour * 60 * 60 + minute * 60 + second;
  }
  </code></pre>