I am not sure about your problem but what you want is should be like the example below:
#include "stdafx.h"
#include<queue>
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
queue<int> boughtn ;
queue<int> soldn ;
queue<int> boughtp ;
queue<int> soldp ;
int boughtnum ;
int boughtprice ;
int soldnum ;
int soldprice ;
int benefit = 0 ;
cout << "Please enter number of bought stocks (enter 0 to end):\n" << endl ;
do
{
cin >> boughtnum ;
boughtn.push (boughtnum);
}
while (boughtnum);
cout << "Please enter price of bought stocks (enter 0 to end):\n" << endl ;
do
{
cin >> boughtprice ;
boughtp.push (boughtprice);
}
while (boughtprice);
cout << "Please enter number of sold stocks (enter 0 to end):\n" << endl ;
do
{
cin >> soldnum ;
soldn.push (soldnum);
}
while (soldnum);
cout << "Please enter price of sold stocks (enter 0 to end):\n" << endl ;
do
{
cin >> soldprice ;
soldp.push (soldprice);
}
while (soldprice);
while ( ( !boughtn.empty() ) & ( !soldn.empty() ) )
{
int &iBoughtn = boughtn.front();
int &iSoldn = soldn.front();
int &iSoldp = soldp.front();
int &iBoughtp = boughtp.front();
if ( iBoughtn > iSoldn )
{
benefit += iSoldn * ( iSoldp - iBoughtp ) ;
}
else
{
benefit += iBoughtn * ( iSoldp - iBoughtp ) ;
}
cout << "The benefit is " << benefit << endl ;
boughtn.pop() ;
boughtp.pop() ;
soldn.pop() ;
soldp.pop() ;
}
return 0;
}