@anonymous234 said in Help Bites:
int main(){
while(true){
if(fireAlert() || intruderAlert() || somethingElseAlert()) soundAlarm();
sleep(500);
}
}
Not answering to the actual question, but the design of the existing code is awful. Instead of a busy loop, consider using events, e.g. in some simplified pseudo-c# without code editor:
private int _houseTemperature;
public delegate void alertDelegate();
public event alertDelegate OnCriticalTemperatureReached;
public int HouseTemperature {
get { return _houseTemperature; }
set {
_houseTemperature = value;
if ( _houseTemperature > 100 ) {
OnCriticalTemperatureReached ();
}
}
}
int main() {
OnCriticalTemperatureReached += new alertDelegate(SoundAlarm);
// wait for user input to terminate program
// ...
}
static void SoundAlarm () {
// sound the alarm
}
... or something like that. Might need threads somewhere. I did not try to run this.
EDIT: I can actually answer the question: In order to enable/disable the alert, all you need to do is subscribe/unsubscribe from the event