title: Warning: "conversion from 'double' to 'int', possible loss of data"
body: <p>I'm working on the following C++ homework question:</p>
  
  <p>"Write a program that lets the user enter the total rainfall for each of 12 months into an array of doubles. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts.</p>
  
  <p><em>Input Validation: Do no accept negative numbers for monthly rainfall figures.</em>"</p>
  
  <p>The errors I am getting are:</p>
  
  <ul>
  <li>Warning  2   warning C4244: '=' : conversion from 'double' to 'int', possible loss of data    </li>
  <li>Warning  4   warning C4244: '=' : conversion from 'double' to 'int', possible loss of data   </li>
  <li>Warning  1   warning C4244:'initializing' : conversion from 'double' to 'int', possible loss of
  data</li>
  <li>Warning  3   warning C4244: 'initializing' : conversion from
  'double' to 'int', possible loss of data</li>
  </ul>
  
  <p>Reading these, I guess it's safe to assume I have several mistakes in my code regarding making doubles into integers. I have combed through my code, looking for these mistakes. Those int variables I found (according to the line direction provided by Visual Studio 2012), I changed to double; but it only messes up my code more and creates more errors. I even went out and made every int variable into a double variable, only to be smacked by well over 20 errors regarding the 'counter' variables; errors saying something about "enum type."</p>
  
  <p>Any help here would be greatly appreciated, this assignment is due by this Thursday afternoon (Oct 9).</p>
  
  <p>This program does compile, but it gives me all kinds of garbage answers and excess garbage ones as well.</p>
  
  <p>Here is my code thus far:</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;string&gt;
  using namespace std;
  
  //Function prototypes
  void totalAndAverage(int, double []);
  void getHighest(int, double [], string []);
  void getLowest(int, double [], string []);
  
  
  //Global integer
  const int SIZE = 12;
  int main()
  {
      //Create arrays
      double rainfallAmount[SIZE];
      int index;
      string months[SIZE] = { "January", "February", "March",
                           "April", "May", "June", 
                           "July", "August", "September", 
                           "October", "November", "December" };
  
      //Get the amount of rain for each month
      for ( index = 0; index &lt; SIZE; index++)
      {
          cout &lt;&lt; "Please enter the amount of rain (in inches) for month " &lt;&lt; (index + 1) &lt;&lt; ": " &lt;&lt; endl; //+1 to not skip an array element
          cin &gt;&gt; rainfallAmount[index];
  
              //input validation, do not accept negative numbers
              while (rainfallAmount[index] &lt; 0)
              {
                  cout &lt;&lt; "You cannot have a negative amount of rainfall. Please enter the amount of rain." &lt;&lt; endl;
                  cin &gt;&gt; rainfallAmount[index];
              }
  
      }
  
      //Call function to find total and average
      totalAndAverage(index, rainfallAmount);
  
      //Call function to find highest
      getHighest(index, rainfallAmount, months);
  
      //Call function o find lowest
      getLowest(index, rainfallAmount, months);
  
  system("pause");
  return 0;
  
  }
  
  
  
  void totalAndAverage(int i, double rainData[])
  {
      double total = 0, average;
  
      //Find the total and average
      for (i = 0; i &lt; SIZE; i++)
      {
          total += rainData[i];
      }
      //Display total
      cout &lt;&lt; "The total rainfall is: " &lt;&lt; total &lt;&lt; endl;
  
      //Find average and display
      average = total / SIZE;
      cout &lt;&lt; "The average monthly rainfall is: " &lt;&lt; average &lt;&lt; endl;
  }
  
  
  
  void getHighest(int iCount, double rainData2[], string monthData[])
  {
      string highestMonth;
  
      //Initialize highest
      int highestRain = rainData2[0];
  
      //Find the highest
      for (iCount = 0; iCount &lt; SIZE; iCount++)
      {
          if (rainData2[iCount] &gt; highestRain)
          {
              highestRain = rainData2[iCount];
              highestMonth = monthData[iCount];
  
              //Display highest
              cout &lt;&lt; highestMonth &lt;&lt; " had the most rainfall this year with " &lt;&lt; highestRain &lt;&lt; " inches." &lt;&lt; endl;
          }
  
      }
  }
  
  
  
  void getLowest(int counter, double rainData3[], string monthDataCopy[])
  {
      string lowestMonth;
  
      //Initialize highest
      int lowestRain = rainData3[0];
  
      //Find the highest
      for (counter = 0; counter &lt; SIZE; counter++)
      {
          if (rainData3[counter] &gt; lowestRain)
          {
              lowestRain = rainData3[counter];
              lowestMonth = monthDataCopy[counter];
  
              //Display highest
              cout &lt;&lt; lowestMonth &lt;&lt; " had the least rainfall this year with " &lt;&lt; lowestRain &lt;&lt; " inches." &lt;&lt; endl;
          }
  
      }
  }
  </code></pre>