title: Function returning NaN in C++
body: <p>I'm creating a software in C++ loops on one function(double) indefinitely. After going through the loop the first time, the second time it runs, it returns 'nan'. Where did I go wrong.</p>
  
  <pre><code>int main()
  {
     double Balance = 100;
  
     for (int i = 0; i &lt; 5; i++) {
        nyaradzo(Balance, i);
     }
  }
  
  double nyaradzo(double bal, int pass)
  {
     int x = bal;
     double Amount;
     string policy_number;
     double confirmation;
  
     cout&lt;&lt;"WELCOME TO NYARADZO ONLINE POLICY PAYMENT"&lt;&lt;endl;
     cout&lt;&lt;"ENTER YOUR POLICY NUMBER"&lt;&lt;endl;
     cin&gt;&gt;policy_number;
     cout&lt;&lt;"ENTER AMOUNT YOU WISH TO PAY FOR YOU POLICY"&lt;&lt;endl;
     cin&gt;&gt;Amount;
     cout&lt;&lt;"YOUR POLICY NUMBER IS: "&lt;&lt;policy_number&lt;&lt;endl;
     cout&lt;&lt;"YOU HAVE CHOSEN TO PAY $"&lt;&lt;Amount&lt;&lt;" FOR YOUR FUNERAL POLICY. \n Is this information correct?"&lt;&lt;endl;
     cout&lt;&lt;"1 TO CONFIRM"&lt;&lt;endl;
     cout&lt;&lt;"2 TO CANCEL"&lt;&lt;endl;
     cin&gt;&gt;confirmation;
     if (confirmation==1) {
        if (Amount &lt;= x) {
           x -= Amount;
           cout&lt;&lt;"Transaction Complete"&lt;&lt;endl;
           cout&lt;&lt;"YOUR BALANCE IS $"&lt;&lt;x&lt;&lt;endl;
           return x;
        }
        else if (Amount &gt; x) {
           cout&lt;&lt;"TRANSACTION DENIED \a"&lt;&lt;endl;
           cout&lt;&lt;"You cannot withdraw more than your actual balance..."&lt;&lt;endl;
           return 0;
        }
        else {
           cout &lt;&lt;x  &lt;&lt; endl;
           cout&lt;&lt;"TRANSACTION DENIED \a"&lt;&lt;endl;
           cout&lt;&lt;"Your purchase must be greater than or at least equal to $1"&lt;&lt;endl;
          return 0;
        }
     }
     else if (confirmation==2) {
        cout&lt;&lt;"YOU HAVE CHOSEN TO CANCEL YOUR ZESA TRANSACTION"&lt;&lt;endl;
        //    transaction(bal, pass);
     }
  
     else 
  
  {
  
  cout &lt;&lt; "Invalid selection" &lt;&lt; endl;
  return 0;
  
  }
      }
  </code></pre>
  
  <p>When it goes through the loop a second time, it fails. </p>