title: How to input sales values multiple times using a For loop and sentinel?
body: <p>To provide some context, I am very new to programming and to C++ so I understand that my code is likely not the most efficient and my error is probably fairly simple. This is just something I am doing for fun and I have a particular interest in music, so that is what has inspired me to create this type of program.</p>
  <p>I am trying to practice what I have learned in class in order to improve my coding. I am working on a program that will: 1) get the name of an album from the user 2) get the number of singles released off the album from the user 3) get the sales of the album from the user 4) get the sales of each single from the user and 5) calculate the total album and single sales off the album.</p>
  <p>So far, my code is working well but I am having some difficulty with the single sales and I am unsure how to code it so that it works properly. I want to use a For loop that asks for the sales of each single. Inside of the loop, I have a nested while loop to stop collecting the sales for a single when &quot;1&quot; is entered by the user. My code works well for the first single, however after I enter &quot;1&quot; to indicate that there are no more sales to be entered for the first single, the For loop just prints out the prompt for the sales of the next singles but does not allow for any entry. I know that this is because of the nested while loop I have included, but I don't know how to make the loop accept user sales input for each single while still being able to mark the end of input for each single using &quot;1&quot; as a sentinel.</p>
  <p>This is what the program looks like when running the For loop and using my own input:</p>
  <p>&quot;What are the sales of single #1?</p>
  <p>-5000000</p>
  <p>-250000</p>
  <p>-320000</p>
  <p>-1</p>
  <p>What are the sales of single #2?</p>
  <p>What are the sales of single #3?</p>
  <p>What are the sales of single #4?</p>
  <p>What are the sales of single #5?</p>
  <p>The single sales are 5570000.&quot;</p>
  <p>I indicated there were 5 singles released off the album but I am only able to enter the sales for the first single. As I mentioned, I know this is because when I entered 1, the nested while loop I am using to collect the sales is terminated and then the For loop just prints out the cout statement I have written. However, I am looking for a way to code this so that I can enter the sales for all 5 singles.</p>
  <p>Does anyone know how I might be able to fix this? I appreciate any help offered and I am happy to answer any additional questions that anyone might have. I am also including the code I have written for the function that handles the single sales for reference but I can include my entire code as well if it would be helpful. Thank you!</p>
  <pre><code>int singleSales(int numOfSingles)
  {
      
  //Holds single sales and accumulated sales
      int singleSales = 0;
      int totalSales = 0;
      
      //Collects the single sales for each single as determined by user
      for (int singleNum = 1; singleNum &lt;= numOfSingles; singleNum++)
      {
          cout &lt;&lt; &quot;\nWhat are the sales of single #&quot; &lt;&lt; singleNum &lt;&lt; &quot;?\n&quot;;
          
          while (singleSales != 1) //Collects single sales while input is not 1
          {
              cin &gt;&gt; singleSales;
              totalSales += singleSales; //Accumulates single sales
          }
      }
      
      return totalSales - 1;
  }
  </code></pre>