以下是我遇到的问题的演示。
do-while循环中的If语句将不会运行。即使“ while”的逻辑完全相同并且可以正确执行。我已逐步解决了调试器的问题,testVar的值为-1.00000000,依此类推。
#include<iostream>
using namespace std;
int main()
{
double testVar = 0.00;
do
{
cout << "Enter variable " << endl;
cin >> testVar;
if (testVar < 0.00) { "Yep!"; } **//Doesn't work.**
} while (testVar < 0.00); **//Works**
return 0;
}
The output of running this program looks like this:
Enter variable
-1
Enter variable
-1
Enter variable
-1
Enter variable
-1
有人可以解释这种现象并提供解决方案吗?我觉得我正在服用疯狂药丸,因为我应该看到“是的!”当testVar = -1.00时。
顺便说一句,我已经用C#和Delphi开发了。我目前正在使用C ++来获得学位要求。
谢谢, 抢
You just have a string literal there - you aren't printing it - you're missing the
cout
call: