I've been working on this code for a simulation, but strange things keep happening. The trader object is (int buy, int inf, int t1). The values of buy and inf should only be 0 or 1, but i keep getting ridiculously high and even negative values and I cant see why. The t1 ends up being around e^-324 sometimes. can anyone tell me why?

Thanks

J

```
for(int i=0; i<512; i=i+2) //loops through the pairs of traders
{
double r1 = rand();
double r2 = rand();
double max = RAND_MAX;
double eta1 = r1/max;
double eta2 = r2/max;
// Generates random numbers eta1, eta2 between 0 and 1
double P1 = order0[i].P_buy(t);
double P2 = order0[i+1].P_buy(t);
if( order0[i].getbuy()==1 )//if i has bought
{
// and if i+1 has bought as well
if( order0[i+1].getbuy() == 1)
{
//then create new level of hierarchy
order1[i] = trader1(order0[i], order0[i+1]);
}
else if( eta2 <= P2 )// if i+1 has not bought, will buy
{
order0[i+1].setbuy(1); //trader buys
//then create new level of hierarchy
order1[i] = trader1(order0[i], order0[i+1]);
}
}
// at this point we know i has not bought
else if( order0[i+1].getbuy() == 1)
{
if( eta1 <= P1 )// if i buys
{
//then create new level of hierarchy
order1[i] = trader1(order0[i], order0[i+1]);
}
}
// so neither has bought, see if they enter market
else if ( eta1 <= P1 && eta2 <= P2 )// if both buy
{
order0[i].setbuy(1);
order0[i+1].setbuy(1);
//create new level of hierarchy
order1[i] = trader1(order0[i], order0[i+1]);
}
else if ( eta1 <= P1 )//only i buys
{
order0[i].setbuy(1);
order0[i+1].setinf(1);// i+1 is influenced
order0[i+1].sett1(t);
}
else if ( eta2 <= P2 )// only i+1 buys
{
order0[i+1].setbuy(1);
order0[i].setinf(1);// i is influenced
order0[i].sett1(t);
}
}
```