c++
We can dynamically resize vectors so that they may grow andshrink. While this is very
convenient, it is inefficient. It is best to know the number ofelements that you need for your vector
when you create it. However, you might come across a situationsomeday where you do not know
the number of elements in advance and need to implement adynamic vector.
Rewrite the following program so that the user can enter anynumber of purchases, instead of just
10 purchases. Output the total of all purchases. Hint: us dowhile loop with your vector..
#include
#include
using namespace std;
int main()
{
vector purchases(10);
for (int i = 0; i < 10; i++)
{
cout << \"Enter a purchase amount\";
cin >> purchases[i];
}
return (0);
}
Write your code here:
Use the Snipping Tool to show output