程序立即结束,为什么
The program ends straight away, why?
这段代码应该反复检查Axiom键盘上D9滑块的状态,并使用它的值来控制频率的音高。
int main()
{
int note;
int modwheel;
float frequency;
while (modwheel != 0)
{
note = aserveGetControl(74);
modwheel = aserveGetControl(01);
frequency = 440 * pow(2, (note-69) /12.0);
aserveOscillator(1,frequency,1.0,0);
aserveSleep(100);
}
return 0;
}
你从不初始化modwheel
,所以当while
循环开始时,它的值是"随机的",即它可以为零,这会导致循环立即结束。
do/while
循环来确保它至少有一个迭代,或者使用内部带有if
的无限while (true)
循环,以避免实际将0
作为有效输入处理。
相关文章:
- 为什么在这个代码结束循环中没有得到结束
- 为什么擦除方法会影响结束方法
- 为什么我的两个 cin 语句没有在程序结束时运行?
- 为什么我的程序在输入某个形状的面积的测量值后没有结束?
- 为什么这个 while 循环在下面的代码中没有结束?
- 为什么在使用不相关的宏时会阻止 while 循环结束?
- 为什么我的 while 循环永远不会在 C++ 中的数字猜测游戏中结束?
- C++ char 数组特征:为什么字符串在数组结束之前停止?
- 为什么我的线程永远不会结束
- 为什么它停止并以退出代码 11 结束?
- 为什么我的 while 语句没有结束?
- 为什么 std::variant 使用开始和结束迭代器进行编译?
- 为什么 while(int) 在 int = 0 时结束?
- 为什么某些共享库以D.So而不是.so结束
- C 为什么在满足布尔条件后,我的DO-while循环就无法结束
- C++ 为什么 getline() 会结束 while 循环
- 为什么循环结束时不这样做?
- 动态内存分配 - 为什么程序结束时没有"delete"?
- 为什么程序在结束后失败
- 有点困惑为什么我的循环没有结束