title: Program to repeat based on user input using nested loop
body: <p>I'm trying to make a nested loop at the bottom of the main function, that if the user enters "y" the program will repeat, if "n" the function will return 0 and stop, and if the user enters some other letter give an error, to re-enter choice.</p>
  
  <p>If I enter "y", the program repeats
  If I enter "n", i get nothing just a blank like
  If I enter "e" i get thrown into an infinite loop</p>
  
  <pre><code>int main() 
  {
  
      //local constants
      const string ENTER_DAYS_RENTED = "Enter the number of days rented: ";
      const string ENTER_MILES_DRIVEN = "Enter number of miles driven: ";
  
      //local variables
      char userCarTypeChosen;
      char anotherBill;
      int daysRented;
      int milesDriven;
      double carCharge;
      double mileageCharge;
      double tax = 0;
      double total = 0;
  
      do 
      {
          //call function to display program description
          displayProgramDescription();
  
          //calls function to validate the car choice input by user
          userCarTypeChosen = validateCarChoice();
  
          //if car type chosen is suv (S) then only prompt will be to enter days
          //rented, if not prompt both days rented and miles driven.
          if (userCarTypeChosen == 'S')
          {
              daysRented = validateNumEntry(ENTER_DAYS_RENTED);
              cout &lt;&lt; endl;
          }
          else
          {   
              daysRented = validateNumEntry(ENTER_DAYS_RENTED);
              cout &lt;&lt; endl;
              milesDriven = validateNumEntry(ENTER_MILES_DRIVEN);
              cout &lt;&lt; endl;
          }
  
          //blank lines between input and output
          cout &lt;&lt; endl &lt;&lt; endl;
  
          //calls function to calculate total car charge
          carCharge = calculateTotalCarCharge(userCarTypeChosen, daysRented);
  
          //calls function to calculate total mileage charge
          mileageCharge = calculateTotalMileageCharge(userCarTypeChosen, 
                          daysRented, milesDriven);
  
          calculateBillTotal(carCharge, mileageCharge, tax, total);
  
          printBill (userCarTypeChosen, daysRented, milesDriven, carCharge,
          mileageCharge, tax, total);
  
          cout &lt;&lt; endl;
          cout &lt;&lt; "Calculate another bill (y/n)? ";
          cin &gt;&gt; anotherBill;
          anotherBill = toupper(anotherBill);
          cout &lt;&lt; endl;
  
      }
          while (anotherBill == 'Y');
  
              if (anotherBill !='N')
              cout &lt;&lt; "Error - Calculate another bill (y/n)?" &lt;&lt; endl;
              cin &gt;&gt; anotherBill;
  
  
      return 0;
  }
  </code></pre>
  
  <p>UPDATE:
  created this function</p>
  
  <pre><code>char validateCalcNewBill()
  {
      char billAgain;
  
      cout &lt;&lt; "Calculate another bill (y/n)?";
      cin &gt;&gt; billAgain;
      cout &lt;&lt; endl;
      billAgain = toupper(billAgain);
  
      while (billAgain != 'Y' &amp;&amp; billAgain !='N')
      {
          cout&lt;&lt; "Error - Calculate another bill (y/n)?";
          cin &gt;&gt; billAgain;
          billAgain = toupper(billAgain);
      }
  
      return billAgain;
  }
  </code></pre>
  
  <p>then at the end of main</p>
  
  <pre><code>//calls function to validate calculating a new bill
          anotherBill = validateCalcNewBill();
  
      }
          while (anotherBill == 'Y');
  
      return 0;
  }
  </code></pre>