C++ How do I reprint values from a loop?

You should start by reading on what vectors are and how they work. Get rid of the while loop. You only need 2 for loops to accomplish the task with the way your code is set up.

vector<float> cash;
......
......
for (int i = 0; i < 5; i++)
    {
        cout << "Enter the cost of the item: ";
        cin >> item;
        //push items into vector here
    }
.....
.....
for (int i = 0; i < cash.size(); i++)
{
    // output like you were doing but with your vector elements
}

With that skeleton code you should be able to accomplish what you want with a little research

Leave a Comment