title: C-F F-C conversion program
body: <p>I am currently designing a program for my class in Programming Fundamentals I.</p>
  
  <p>The teacher is asking me to do a while loop to continue the program, but circulate a new session after the user decided to end the session.  I already have designed a do while loop for this purpose so that it can continue to pre-evaluate what's necessary.</p>
  
  <p>My problem doesn't start with the do while loop.  It starts with the part of trying to enter a value after the end user has entered an invalid one.  I will highlight the bold to show you the problem:</p>
  
  <p>Here's the code:</p>
  
  <pre><code>do {
      cout &lt;&lt; "\nPlease choose your method of conversion: " &lt;&lt; endl;
      cout &lt;&lt; "1 - C to F" &lt;&lt; endl;
      cout &lt;&lt; "2 - F to C" &lt;&lt; endl;
      cout &lt;&lt; "Enter a number: ";
      cin &gt;&gt; userInput;
      cout &lt;&lt; endl;
  
      if (userInput == 1)
      {
          cout &lt;&lt; "The formula to convert Celsius to Fahrenheit is " &lt;&lt; endl;
          cout &lt;&lt; "F = (C * 9 / 5) + 32.\n" &lt;&lt; endl;
          cout &lt;&lt; "Enter a value to convert: ";
          cin &gt;&gt; C;
  
          if (C)
          {
              F = (C * 9 / 5) + 32;
              cout &lt;&lt; setprecision(1) &lt;&lt; fixed &lt;&lt; showpoint;
              cout &lt;&lt; "\nYou entered " &lt;&lt; C &lt;&lt; " and converted it to " &lt;&lt; F &lt;&lt; endl;
          }
  
          **else if (!C)
          {
              cout &lt;&lt; "Please enter a valid value to convert.";
          }**
      }
  
      else if (userInput == 2)
      {
          cout &lt;&lt; "The formula to convert Fahrenheit to Celsius is " &lt;&lt; endl;
          cout &lt;&lt; "C = (F -32) * 5 / 9.\n" &lt;&lt; endl;
          cout &lt;&lt; "Enter a value to convert: ";
  
          if (F)
          {
              cin &gt;&gt; F;
              C = (F - 32) * 5 / 9;
              cout &lt;&lt; setprecision(1) &lt;&lt; fixed &lt;&lt; showpoint;
              cout &lt;&lt; "\nYou entered " &lt;&lt; F &lt;&lt; " and converted it to " &lt;&lt; C &lt;&lt; endl;
          }
          **else if (!F)
          {
              cout &lt;&lt; "Please enter a valid value to convert.";
          }**
      }
  
  cout &lt;&lt; "Do you want to convert again? (Y/N): ";
  cin &gt;&gt; endSession;
  
  } while (endSession == 'Y');
  </code></pre>
  
  <p>What I want to do for else if !(C or F) is to make sure that I can input the correct value, return the value, then calculate.  I want to make sure that even if the end user made errors in computing the correct value even after the first time, the end user will continue the program until a correct value is entered.  Once that's entered, the do while loop then ends the session if the user wants to convert again.</p>
  
  <p>I have tried either while inside the nested if else ifs; C&amp;P'd the conversion value into the else if !(), producing a continuous error non-stop.  Even though I don't ask for the straight answer, some helpful hints or pointing in the right direction would literally help.  In fact, it would help if it was basic.</p>