title: C++: Why must I order my declaration as a double in this manner?
body: <p>so one of my assignments was to make a program that converts currencies, this one below converts U.S. dollars to certain south american dollars.</p>
  <p>I'm not sure why I can't declare a variable for US dollars along with the variable for the other currencies. I did it this way, and the program screwed up the conversion:</p>
  <pre><code>double dollars;
  
  double pesos = dollars * 26;
  
  double reais = dollars * 5.9;
  
  double soles = dollars * 3.53;
  
  std::cout &lt;&lt; &quot;Enter the number of U.S. dollars you have:&quot;;
  std::cin &gt;&gt; dollars;
  
  std::cout &lt;&lt; &quot;In colombian pesos, that's &quot; &lt;&lt; pesos &lt;&lt; &quot;\n&quot;;
  std::cout &lt;&lt; &quot;In brazilean reals, that's &quot; &lt;&lt; reais &lt;&lt; &quot;\n&quot;;
  std::cout &lt;&lt; &quot;In peruvian soles, that's &quot; &lt;&lt; soles &lt;&lt; &quot;\n&quot;;
  </code></pre>
  <p>the input/output was this:</p>
  <pre><code>Enter the number of U.S. dollars you have:1
  In colombian pesos, that's 0
  In brazilean reals, that's 0
  In peruvian soles, that's 0
  </code></pre>
  <p>However, when i run the code this way (putting the input directly after the declaration of <code>dollars</code>), the input performs the correct conversion:</p>
  <pre><code>double dollars;
  
  std::cout &lt;&lt; &quot;Enter the number of U.S. dollars you have:&quot;;
  std::cin &gt;&gt; dollars;
  
  double pesos = dollars * 26;
  
  double reais = dollars * 5.9;
  
  double soles = dollars * 3.53;
  
  std::cout &lt;&lt; &quot;In colombian pesos, that's &quot; &lt;&lt; pesos &lt;&lt; &quot;\n&quot;;
  std::cout &lt;&lt; &quot;In brazilean reals, that's &quot; &lt;&lt; reais &lt;&lt; &quot;\n&quot;;
  std::cout &lt;&lt; &quot;In peruvian soles, that's &quot; &lt;&lt; soles &lt;&lt; &quot;\n&quot;;
  </code></pre>
  <p>I didn't think where i place the declaration of the variable mattered, as long as i declared it before using it.</p>