Hello, I am trying to create a shop where the user can pick an item to add to their cart and after they pick the item, I want to remove it from the list, but I can't seem to remember on how to do it.
int main( void )
{
const int nSize = 5;
CWeapons Weapons[nSize];
// Set each Weapons w/ unique names
Weapons[0].Set( "Batarang", 59.99f, 1);
Weapons[1].Set( "KeyBlade", 39.99f, 1);
Weapons[2].Set( "Katana", 39.99f, 1);
Weapons[3].Set( "Flail", 39.99f, 1);
Weapons[4].Set( "Assult Rifle", 39.99f, 1);
const int nCartSize = 5;
int nUser;
CQueue Queue(nCartSize);
// shopping menu
for(;;)
{
cout << "1) Add an Item to the cart\n"
<< "2) Check Out\n"
<< "What would you like to do:";
if(cin >> nUser && nUser <= 2 && nUser >=1 )
{
cin.ignore(INT_MAX, '\n');
break;
}
cin.clear();
cin.ignore(INT_MAX, '\n');
}
// if user selects add items to the cart
if(1 == nUser)
{
int nCheckOut;
for(;;)
{
// show selextion of 5 Weapons
for(int i = 0; i < nCartSize; ++i)
{
cout << i+1 << ") " << Weapons[i].GetName() << " - " << Weapons[i].GetCost() << '\n';
}
cout << "0) Check Out Early\n";
// ask user what option they want to do (0-5)
for(;;)
{
cout << "What weapon would you like to add: ";
if(cin >> nCheckOut && nCheckOut >=0 && nCheckOut <=5 )
{
cin.ignore(INT_MAX, '\n');
break;
}
cin.clear();
cin.ignore(INT_MAX, '\n');
}
if(nCheckOut == 1)
{
Queue.Enqueue(Weapons[0]);
}
else if(nCheckOut == 2)
{
Queue.Enqueue(Weapons[1]);
}
else if(nCheckOut == 3)
{
Queue.Enqueue(Weapons[2]);
}
else if(nCheckOut == 4)
{
Queue.Enqueue(Weapons[3]);
}
else if(nCheckOut == 5)
{
Queue.Enqueue(Weapons[4]);
}
else
break;
system("pause");
cout << "\n\n";
}
}
cout << "Receipt\n"
<< "=======\n";
float fTotal = 0;
while(Queue.Dequeue(Weapons[nCartSize]))
{
cout << Weapons[nCartSize].GetName() << " - " << Weapons[nCartSize].GetCost() << '\n';
fTotal += Weapons[nCartSize].GetCost();
}
cout << "Total: " << fTotal;
this is my loop where I ask the user to pick an item, but I can't remember on how to remove it from the list of items in the loop.