title: Array Program Weird Output
body: <p>I am trying to write a code to list gas mileage, and so far it works.  The problem is that it does not work the way it should. The code below asks for input and then displays a list of said input along with the calculated MPG.</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  //function prototype
  void CalcAverage (int arr1[], float arr2[], int size);
  //global variables
  int mil [3];
  float gal [3];
  float mpg [3];
  //main program
  int main()
  {
  char month [7];
  int day [3];
  cout &lt;&lt; "Please enter the starting month" &lt;&lt; endl;
  cin &gt;&gt; month;
  
  cout &lt;&lt; "Please enter starting day entry 1" &lt;&lt; endl;
  cin &gt;&gt; day [0];
  cout &lt;&lt; "entry 2" &lt;&lt; endl;
  cin &gt;&gt; day [1];
  cout &lt;&lt; "entry 3" &lt;&lt; endl;
  cin &gt;&gt; day [2];
  cout &lt;&lt; "entry 4" &lt;&lt; endl;
  cin &gt;&gt; day [3];
  
  cout &lt;&lt; "Please enter gallons entry 1" &lt;&lt; endl;
  cin &gt;&gt; gal [0];
  cout &lt;&lt; "entry 2" &lt;&lt; endl;
  cin &gt;&gt; gal [1];
  cout &lt;&lt; "entry 3" &lt;&lt; endl;
  cin &gt;&gt; gal [2];
  cout &lt;&lt; "entry 4" &lt;&lt; endl;
  cin &gt;&gt; gal [3];
  
  cout &lt;&lt; "Please enter miles entry 1" &lt;&lt; endl;
  cin &gt;&gt; mil [0];
  cout &lt;&lt; "entry 2" &lt;&lt; endl;
  cin &gt;&gt; mil [1];
  cout &lt;&lt; "entry 3" &lt;&lt; endl;
  cin &gt;&gt; mil [2];
  cout &lt;&lt; "entry 4" &lt;&lt; endl;
  cin &gt;&gt; mil [3];
  
  CalcAverage (mil,gal,4);
  
  cout &lt;&lt; "Week of" &lt;&lt; "\t\tGallons" &lt;&lt; "\t\tMiles" &lt;&lt; "\t\tMPG" &lt;&lt; endl;
  cout &lt;&lt; "_ _ _ _ _ _ _" &lt;&lt; "\t_ _ _ _ _" &lt;&lt; "\t_ _ _ _"  &lt;&lt; "_ _ _ _" &lt;&lt; endl;
  cout &lt;&lt; month &lt;&lt;  " " &lt;&lt; day [0] &lt;&lt; "\t" &lt;&lt; gal [0] &lt;&lt; "\t\t" &lt;&lt; mil [0] &lt;&lt; "\t\t" &lt;&lt; mpg [0] &lt;&lt;     endl;
  cout &lt;&lt; month &lt;&lt;  " " &lt;&lt; day [1] &lt;&lt; "\t" &lt;&lt; gal [1] &lt;&lt; "\t\t" &lt;&lt; mil [1] &lt;&lt; "\t\t" &lt;&lt; mpg [1] &lt;&lt;     endl;
  cout &lt;&lt; month &lt;&lt;  " " &lt;&lt; day [2] &lt;&lt; "\t" &lt;&lt; gal [2] &lt;&lt; "\t\t" &lt;&lt; mil [2] &lt;&lt; "\t\t" &lt;&lt; mpg [2] &lt;&lt;     endl;
  cout &lt;&lt; month &lt;&lt;  " " &lt;&lt; day [3] &lt;&lt; "\t" &lt;&lt; gal [3] &lt;&lt; "\t\t" &lt;&lt; mil [3] &lt;&lt; "\t\t" &lt;&lt; mpg [3] &lt;&lt;     endl;
  
  system("PAUSE");
  
  }
  //function definition
  void CalcAverage (int arr1[], float arr2[], int size)
  {
  //statements
  mpg [0] = mil [0] / gal [0];
  mpg [1] = mil [1] / gal [1];
  mpg [2] = mil [2] / gal [2];
  mpg [3] = mil [3] / gal [3];
  
  }
  </code></pre>
  
  <p>The code works and I do not get any errors.  However, when the code displays the output, some of the results are switched or jumbled, or completely random (my 3rd gal input becomes my 1st mil input etc.) What is causing this problem, and how can I fix it?</p>