知道为什么否则将永远不会执行该陈述吗?程序运行时,差值会不断变化。
double difference = abs(reale_x[0] - reale_x[1]);
if (0 <= difference < 45) {
timer_counter += 1;
if (timer_counter == 30) {
cout << "CLICK" << '\n';
}
}
else if (difference > 50) {
timer_counter = 0;
}
比较不是在c ++中工作的方式。
这段代码是什么
if (0 <= difference < 45) {
它首先比较0是否小于或等于difference
。然后用布尔值true或false“替换”它。然后将bool值(因此1或0)与45进行比较。它将始终小于45。您拥有的始终是真实的语句。
因此,您编写if语句的方式是
if (difference >= 0 && difference < 45){
请注意,由于您的else if语句,如果差异> 44和<51,它将不会执行
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句