Hello,
I cannot figure out why my program crashes when it gets to the code below. Everything else in my coding works, except when I go to run this code...
void Auctioneer::matchingGame(){
vector<Trader>::iterator it;
int i=ask.size()-1;
int x=0;
int y=0;
int bId;
int tId;
char h;
int temp=0;
int p;
it=ask.end();
while(it != ask.begin()){
if(ask[i].getPrice()<=buy[i].getPrice()){//compare prices
temp=(buy[i].getQuan()-ask[i].getQuan());
h = buy[i].getType();
bId = buy[i].getBidId();
tId = buy[i].getTraderId();
p = buy[i].getPrice();
if (temp <0){
temp = (ask[i].getQuan()-buy[i].getQuan());
h = ask[i].getType();
bId = ask[i].getBidId();
tId = ask[i].getTraderId();
p = ask[i].getPrice();
}
matchedAsk[x]=ask[i];
matchedBuy[x]=buy[i];
ask.pop_back();
buy.pop_back();
if(h == 'A'){
ask[i].setUP(bId,tId,h,temp,p);
}else if(h=='B'){
buy[i].setUP(bId,tId,h,temp,p);
}
}else if (ask[i].getPrice()>buy[i].getPrice()){
unmatchedBuy[y]=buy[i];
buy.pop_back();
}
--it;
i--;
x++;
y++;
}
int ab = ask.size()-1;
for (it=ask.end();it !=ask.begin();--it){
unmatchedAsk[y]=ask[ab];
ask.pop_back();
ab--;
}
}
The above code is suppose to match bids then move them to the respective vector (matchedAsk and matchedBuy) by copying the elements to it then erasing the bid that was in the ask OR buy vector. For the bids that do not match, they are moved to the unmatchedAsk and/or unmatchedBuy vector then removed from the ask OR buy vector.
Any help will be appreciated.