title: Calculating values from a while loop?
body: <p>I need to use data entered into my while loop to calculate a sum and a max value. I'm confused as to how I can take the user input for each "day" I have stored as "weathervalue" and use it in a formula to outside the loop. Here is my code.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main ()
  {
  double weatherdays;
  double weathervalue;
  double counter;
  double day;
  
  cout &lt;&lt; "Enter the number of days for which you have weather data - ";
  cin &gt;&gt; weatherdays;
  
  counter = 1;
  day = 1;
  
  while (counter &lt;= weatherdays)
  {
      counter++;
  
      cout &lt;&lt; "What is the rainfall for day " &lt;&lt; day &lt;&lt; endl;
      cin &gt;&gt; weathervalue;
  
      cout &lt;&lt; "What is the max temp for day " &lt;&lt; day &lt;&lt; endl;
      cin &gt;&gt; weathervalue;
  
      day = day + 1;
  }
  
  weathervalue = //formula for sum of rainfall values entered in while loop
  
  cout &lt;&lt; "The total rainfall is " &lt;&lt; weathervalue &lt;&lt; endl;
  
  weathervalue = //formula for max temp values entered in while loop
  
  cout &lt;&lt; "The max temperature is " &lt;&lt; weathervalue &lt;&lt; endl;
  </code></pre>