title: Parallel array in C++
body: <p>I have an assignment where we need to have 2 parallel arrays one is a list of city names and the other is sales amounts. Here is a copy of the problem:</p>
  
  <p><b>Program Description:</b></p>
  
  <p>It needs to compile sales totals for various cities in the USA. Specifically, when the program is run, the user will be prompted to enter a city. If the city is correct, the user will then be prompted to enter a sales amount. If the city doesn’t exist on the list, the user will get an error message (and no sales amount prompt). If a sales amount is entered, it will accumulate into a total for that city. Either way (city exists on the list or not) , the user will then be asked to enter another city or quit.
   Once the user quits, the city name and total should be displayed for all cities, one per line. Following that the program should stop.</p>
  
  <p>There are only 8 cities to choose from.  2 parallel arrays must be used, initialized as follows:</p>
  
  <pre><code>City (String)  Sales (Integer)
  -------------  ---------------
  Atlanta              0
  Buffalo              0
  Chicago              0
  Dallas               0
  Houston              0
  Honolulu             0
  Miami                0
  Reno                 0
  </code></pre>
  
  <p>All input is guaranteed to be single-word followed by enter only. It may not  match a city name, but there will be no spaces. This keeps your program simple as  it lets you avoid using getline( ), which would be needed to deal with blanks between words.
  Sales data is guaranteed good when input.</p>
  
  <p>When I attempted to run my program, visual studios went crazy, and I've pulled out my hair trying to fix it. If someone could help give me some pointers on what I've done wrong, I would greatly appreciate it. Here is a copy of my program:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  int main()
  {
      //declare city and sales array
      string city[8] = {" "};
      int sales[8] = {0};
  
      //declare variables
      string cityName = " ";
      int cityTotal = 0;
      int salesAmt = 0;
      int i = 0;
      char another = ' ';
  
      //init city array
      city[0] = "Atlanta";
      city[1] = "Buffalo";
      city[2] = "Chicago";
      city[3] = "Dallas";
      city[4] = "Houston";
      city[5] = "Honololu";
      city[6] = "Miami";
      city[7] = "Reno";
  
      do
      {
          //input city name and if found input sales amount
          cout &lt;&lt; "Enter a City: Atlanta, Buffalo, Chicago, Dallas, Houston, Honololu, Miami, or Reno: ";
          cin &gt;&gt; cityName;
  
          for(i = 0; i &lt;= 8; i++)
          {
              if(cityName == city[i])
                  {cout &lt;&lt; "Enter sales amount: ";
                   cin &gt;&gt; salesAmt;
                   salesAmt += sales[i];}
              else
                  {cout &lt;&lt; "ERROR: CITY NOT AVAILIABLE" &lt;&lt; endl;
                   cout &lt;&lt; endl;}
              //end if
          }
          //end for loop
  
          //ask if another city
              cout &lt;&lt; "Enter another city?: ";
              cin &gt;&gt; another;
  
      } //end do loop
      while(another == 'Y' || another == 'y');
      {
          for(i = 0; i &lt;= 8; i++)
          {
              cout &lt;&lt; "City: " &lt;&lt; "           " &lt;&lt; "Sales: " &lt;&lt; endl;
              cout &lt;&lt; city[i] &lt;&lt; "          " &lt;&lt; sales[i] &lt;&lt; endl;
          }
          //end for loop
      } //end while loop
  
      system("pause");
      return 0;
  } //end of main
  </code></pre>