title: boolean statement to change 24 hour format to 12 hour format for time equations in a switch menu?
body: <p>So I have a project that requires me to basically make a clock/watch. The default format of the code is a 24 hour format but option 5 in the menu, "toggle 24 hour format", it is required that hour formats change to a 12 hour format. It is not required to keep the previous input of the 24 hours, example: the user inputs 23:45, then presses option 5, then option 4, it shouldn't display 11:45pm. The user should go back to option 1 to input a new time and input an 'a' to choose am or 'p' to choose pm. My question is, how to write a boolean statement so when the user inputs '5' in the switch, the void functions know the format is now the 12 hour format and do a variation of the equations so they deal with 12 hour times.</p>
  
  <p>The problem I see happening is the subtraction or addition functions in a 12 hour format. How would I write the 12 hour addition and subtraction statements so if the time is 12:30 and 45 minutes is added, the new time gets outputted as 1:15 and not 13:15.</p>
  
  <p>I have some idea of how to do it (I'm terrible with boolean logic and functions):</p>
  
  <pre><code>bool mode
      if (mode==true)
      {
          \\12 hour format
      }
      else (mode==false)
      {
          \\24 hour format
      }
  </code></pre>
  
  <p>But I have no idea how to format that and make it so the option 5 changes the mode. I kind of understand how to do it in the void functions: </p>
  
  <p><em>if mode==true</em>
  <em>then add hours and minutes as a 12 hour format</em></p>
  
  <p>But again, confused on how to do this. I looked at a similar problem posted about 6 days ago, but the answer didn't satisfy me, and only dealt with a single input and made it so the user has to input 24 or 12 to denote the time instead of making it so option 5 toggles to mode. It did use:</p>
  
  <pre><code>mode= !mode
  </code></pre>
  
  <p>which looked promising so that if option 5 is toggled, the user can input option 5 again and make the format toggle again, but again: how do I make it so option 5 toggles the mode?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;sstream&gt;
  
  using namespace std;
  
  void calcDeltaFutr(int h, int m, int deltaH, int deltaM, int&amp; hNew, int&amp; mNew);
  void calcDeltaPast(int h, int m, int deltaH, int deltaM, int&amp; hNew, int&amp; mNew);
  void getTime(int &amp;h, int &amp;m, bool mode);
  void rollTimeForward(int&amp; h, int&amp; m);
  void rollTimeBack(int&amp; h, int&amp; m);
  void printTime(int h, int m, bool mode);
  
  void calcDeltaFutr(int h, int m, int deltaH, int deltaM, int&amp; hNew, int&amp; mNew)
  {
      cout &lt;&lt; "Enter a new time:" &lt;&lt; endl &lt;&lt; "Hours: ";
      cin &gt;&gt; deltaH;
      cout &lt;&lt; "Minutes: ";
      cin &gt;&gt; deltaM;
      hNew = h + deltaH;
      mNew = m + deltaM;
      rollTimeForward(hNew, mNew);
      cout &lt;&lt; "The new time is: " &lt;&lt; hNew &lt;&lt; ":" &lt;&lt; mNew &lt;&lt; endl;
      return;
  }
  void calcDeltaPast(int h, int m, int deltaH, int deltaM, int&amp; hNew, int&amp; mNew)
  {
      cout &lt;&lt; "Enter a new time:" &lt;&lt; endl &lt;&lt; "Hours: ";
      cin &gt;&gt; deltaH;
      cout &lt;&lt; "Minutes: ";
      cin &gt;&gt; deltaM;
      hNew = h - deltaH;
      mNew = m - deltaM;
      rollTimeBack(hNew, mNew);
      cout &lt;&lt; "The new time is: " &lt;&lt; hNew &lt;&lt; ":" &lt;&lt; mNew &lt;&lt; endl;
      return;
  }
  void getTime(int &amp;h, int &amp;m, bool mode)
  {
      cout &lt;&lt; "Enter a time (hours, minutes): ";
      cin &gt;&gt; h;
      cin &gt;&gt; m;
      if (h&gt;23 || m&gt;59 || h&lt;0 || m&lt;0)
      {
          cout &lt;&lt; "Invalid input! Please input a value for hours below 24 and a value of minutes below 60." &lt;&lt; endl;
      }
      return;
  
  }
  void rollTimeForward(int&amp; h, int&amp; m)
  {
      h = h + m / 60;
      m = m % 60;
      h = h % 24;
      return;
  }
  void rollTimeBack(int&amp; h, int&amp; m)
  {
      h = h - m / 60;
      m = m % 60;
      return;
  }
  void printTime(int h, int m, bool mode)
  {
      cout &lt;&lt; "The current time is: ";
      cout &lt;&lt; h &lt;&lt; ":" &lt;&lt; m &lt;&lt; endl;
  
  
  
  }
  int h, m, deltaH, deltaM, hNew, mNew;
  bool mode;
  char time;
  
  int main()
  {
      int choice;
      do
      {
          cout &lt;&lt; "-----MENU-----" &lt;&lt; endl &lt;&lt; endl &lt;&lt; "1-Enter a time" &lt;&lt; endl &lt;&lt; "2-Add delta to time" &lt;&lt; endl &lt;&lt; "3-Subtract delta from time" &lt;&lt; endl &lt;&lt; "4-Display current time" &lt;&lt; endl &lt;&lt; "5-Toggle 24 hour mode" &lt;&lt; endl &lt;&lt; "6-exit" &lt;&lt; endl;
          cin &gt;&gt; choice;
  
          switch (choice)
          {
          case 1:
              getTime(h, m, mode);
              continue;
          case 2:
              calcDeltaFutr(h, m, deltaH, deltaM, hNew, mNew);
              continue;
          case 3:
              calcDeltaPast(h, m, deltaH, deltaM, hNew, mNew);
              continue;
          case 4:
              printTime(h, m, mode);
              continue;
          case 5:
              cout &lt;&lt; "12 hour mode turned on" &lt;&lt; endl;
              continue;
          case 6:
              cout &lt;&lt; "Exiting...";
              break;
          }
          if (choice != 1 &amp;&amp; choice != 2 &amp;&amp; choice != 3 &amp;&amp; choice != 4 &amp;&amp; choice != 5 &amp;&amp; choice != 6)
          {
              cout &lt;&lt; "Invalid input! Please try again!" &lt;&lt; endl &lt;&lt; endl;
          }
          else
          {
              break;
          }
      } while (choice != 6);
  
  
      return 0;
  }
  </code></pre>