title: For or While loop with 2 max variables, one of which being an array (Programming I)
body: <p>I have the following assignment for my Programming I class:</p>
  
  <blockquote>
    <p>Prompt for the price of each item.  Store each item price in the array named prices.  When the user has reached $1,000 or 5 items, 
    print out how much was spent, how many items were bought, how much is left, and the average price.<br>
    Print a table of the prices of the items bought.  </p>
  </blockquote>
  
  <p>My original attempt got very mangled:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  using namespace std;
  
  int main ()
  {
      int cost = 1;
      int total = 0;
      int i = 0;
      const int MAXNUM = 5;
      int prices[MAXNUM];
  
  
      while (total &lt; 1000 &amp;&amp; cost !=0 &amp;&amp; i &lt; MAXNUM)
      {
          for (int x = 0; i &lt; MAXNUM; i++)
          {
              cout &lt;&lt; "Please enter the price of the item you are purchasing:"&lt;&lt; endl &lt;&lt; i+1 &lt;&lt; "." &lt;&lt;"$";
              cin &gt;&gt; cost;
              total+=cost;
          }
  //          total += cost;
      }
  /*  
  
  
  //      cout &lt;&lt; \n &lt;&lt; "Name: ";
  //      cin &gt;&gt; name;
      } */
      cout &lt;&lt; "You spent $" &lt;&lt; total &lt;&lt; " by purchasing " &lt;&lt; /* **************** &lt;&lt; */ " items, you have $" &lt;&lt; 1000-total &lt;&lt;/* " leftover, and your average price was $" &lt;&lt;  total/ ******** &lt;&lt; */ "." &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>
  
  <p>So I started over from scratch and so far I have this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;iomanip&gt;
  using namespace std;
  
  int main()
  {
    const int NUMELS = 5;
  
    int i, prices[NUMELS];
    string items [NUMELS];
  
    for (i = 0; i &lt; NUMELS; i++)   
    {
      cout &lt;&lt; "Enter the name of the product: ";
      cin  &gt;&gt; items[i];
      cout &lt;&lt; "Enter the price of the product: $";
      cin  &gt;&gt; prices[i];
    }
    cout &lt;&lt; endl;
    for (i = 0; i &lt; NUMELS; i++)    
        cout &lt;&lt; items[i]&lt;&lt; " cost you $"&lt;&lt; prices[i]&lt;&lt; endl;
  
    return 0;
  }
  </code></pre>
  
  <p>My biggest difficulty right now is trying to have the program check so that the price doesn't go over $1000 (Which I've written a program for in the past) while ALSO checking to make sure the user purchases no more than 5 items.  There are more steps after all of this but once I figure out the base I should be able to build the rest on my own.</p>
  
  <p>I tried putting       if (acc > 1000) 
          break;  at the end of my for loop, but then <a href="https://i.gyazo.com/4b05b24c6c2aa70a51534448528a8c65.png" rel="nofollow">this happened...</a></p>
  
  <p>Thanks in advance!!</p>