评估错误的条件语句

时间:2014-09-16 01:44:57

标签: c++

根据以下程序,如果donuts = 1它将0分配给donuts,但如果我执行此操作,则会显示0已分配给donuts }。请告诉我我在看什么。因为我怎么看这个代码甜甜圈应该等于12,因为甜甜圈应该落入其他地方:

#include <iostream> // Header file to enable console I/O
#include <string>   // Header file to enable string
#include <iomanip>  // enables maniplution of io strem
using namespace std;

// Begin main Function Definition
int main()
{
int donuts = 10;
if (donuts = 1)
{
    donuts = 0;
}
else
{
    donuts += 2;
}
cout<< donuts;
system("PAUSE");
return 0;

}
// End of main function

1 个答案:

答案 0 :(得分:2)

if (donuts = 1)

应该是:

if (donuts == 1)
        //^^^

您需要使用逻辑等于==或赋值=

相关问题