Beginners easy coding question?

 

Hello,

i want to write a simple code that prints out the value of a counter variable that starts at zero and then counts upwards by 1 each time a tick comes through. My code does not work for some reason and i am stuck. here is the code i'm using:

int start()
{

int Counter;

if ( IsTradeAllowed() ) {
Counter=Counter+1;
Print("Counter = ",Counter);
}

return(0);

}

Thanks in advance to any one that can help me write this simple code.

Regards

Rod

 

the counter is reset every time the start function is called.

2 solutions

1) set the counter static

int start()
{

static int Counter=0;

if ( IsTradeAllowed() ) {
Counter=Counter+1;
Print("Counter = ",Counter);
}

return(0);

}

2) set the counter global

int Counter = 0;

int start(){

if ( IsTradeAllowed() ) {
Counter=Counter+1;
Print("Counter = ",Counter);
}

return(0);
}
 
Russell wrote >>

the counter is reset every time the start function is called.

2 solutions

1) set the counter static

2) set the counter global


thanks Russell, that makes perfect sense now. really appreciate it. regards Rocket.