题目正误的判断有错,请注意右侧错误代码,正确代码实例如下:
int main()
{
bool isFlag = false;
if(myNum::x % 2 == 0)
{
isFlag=false;
}
else
{
isFlag = true;
}
if(isFlag == true)
{
cout << "变量" << myNum::x << "是奇数" << endl;
}
else
{
cout << "变量" << myNum::x << "是偶数" << endl;
}
return 0;
}
int main()
{
bool isFlag = false;
if(myNum::x % 2 == 0)
{
isFlag=false;
}
else
{
isFlag = true;
}
if(isFlag == true)
{
cout << "变量" << myNum::x << "是奇数" << endl;
}
else
{
cout << "变量" << myNum::x << "是偶数" << endl;
}
return 0;
}
#include <iostream>
#include <stdlib.h>
using namespace std;
namespace myNum
{
int x = 105;
}
int main()
{
bool isOdd = false;
if(myNum::x % 2 == 0)
{
bool isOdd (false);
}
else
{
bool isOdd (true);
}
if(isOdd)
{
cout << "x是奇数" << endl;
}
else
{
cout << "x是偶数" << endl;
}
return 0;
}
#include <stdlib.h>
using namespace std;
namespace myNum
{
int x = 105;
}
int main()
{
bool isOdd = false;
if(myNum::x % 2 == 0)
{
bool isOdd (false);
}
else
{
bool isOdd (true);
}
if(isOdd)
{
cout << "x是奇数" << endl;
}
else
{
cout << "x是偶数" << endl;
}
return 0;
}