Saving each iteration of an accumulator?
<p>(Yes this WAS homework, but already completed, I'm just trying to improve it now for practice) </p>

<p>This is basically a sales calculator, that allows you to have multiple inputs for sales items, then displays the total, sales tax, and grand total. </p>

<p>The modification I'm trying to make, is that I want to be able to SAVE the cost of each number of items in a variable, without them overlapping memory, and then be able to call them above the grand total, so you can see what each item was worth.</p>

<p>===========================================================================</p>

<pre><code>//importing libraries for cin and cout, as well as setw() and setprecision()
#include &lt;iostream&gt;
#include &lt;iomanip&gt;
using namespace std; //sets all code to standard syntax

int main(){ //initializes the main function

    //initializing variables
    char answer = ' ';
    int saleItems = 0;
    double saleTax = 0.0;
    double grandTotal = 0.0;
    double itemValue = 0.0;
    double titemValue = 0.0;
    double taxPerc = 0.0;

    //begins a post-test loop
    do {
        titemValue = 0.0; //makes sure the accumulator resets WITHIN the loop

        //prompts for sale items amount
        cout &lt;&lt; "How many sales items do you have? : ";
        cin &gt;&gt; saleItems;

        //creates a loop that displays the prompt for each iteration of saleItems
        for (int x = 1; x &lt;= saleItems; x += 1){
            cout &lt;&lt; "Enter in the value of sales item " &lt;&lt; x &lt;&lt; " : $";
            cin &gt;&gt; itemValue;
            titemValue += itemValue; //accumulator for adding up the iterated values
        }

        //prompts the user to enter a sales percentage
        cout &lt;&lt; endl &lt;&lt; endl;
        cout &lt;&lt; "Enter in the sales tax percentage(Enter 10 for 10%): ";
        cin &gt;&gt; taxPerc;
        cout &lt;&lt; endl &lt;&lt; endl;

        //processes the variables after taxPerc has been given
        saleTax = titemValue * (taxPerc / 100);
        grandTotal = titemValue + saleTax;

        //sets decimal precision to 2 places
        cout &lt;&lt; fixed &lt;&lt; setprecision(2);

        //displays receipt with the calculated and input values
        cout &lt;&lt; "********************************************" &lt;&lt; endl;
        cout &lt;&lt; "********  S A L E S  R E C E I P T  ********" &lt;&lt; endl;
        cout &lt;&lt; "********************************************" &lt;&lt; endl;
        cout &lt;&lt; "**                                        **" &lt;&lt; endl;
        cout &lt;&lt; "**                                        **" &lt;&lt; endl;
        cout &lt;&lt; "**                                        **" &lt;&lt; endl;
        cout &lt;&lt; "**                                        **" &lt;&lt; endl;
        cout &lt;&lt; "**  Total Sales            $" &lt;&lt; setw(9) &lt;&lt; titemValue &lt;&lt; "     **" &lt;&lt; endl;
        cout &lt;&lt; "**  Sales Tax              $" &lt;&lt; setw(9) &lt;&lt; saleTax &lt;&lt; "     **" &lt;&lt; endl;
        cout &lt;&lt; "**                          ----------    **" &lt;&lt; endl;
        cout &lt;&lt; "**  Grand Total            $" &lt;&lt; setw(9) &lt;&lt; grandTotal &lt;&lt; "     **" &lt;&lt; endl;
        cout &lt;&lt; "**                                        **" &lt;&lt; endl;
        cout &lt;&lt; "**                                        **" &lt;&lt; endl;
        cout &lt;&lt; "********************************************" &lt;&lt; endl &lt;&lt; endl &lt;&lt; endl;

        //prompts user to begin loop again
        cout &lt;&lt; "Do you want to run this program again? (Y/N):";
        cin &gt;&gt; answer;
        answer = toupper(answer);
        cout &lt;&lt; endl &lt;&lt; endl;

        } while (answer == 'Y');
</code></pre>

<p>===========================================================================</p>

<p>So, essentially, I need to be able to save each itemValue to multiple different values without the loop repeating itself, and just replacing them, and I can't really see how I can do that considering the accumulator will just keep looping, and adding up the itemValue values. </p>