#include?<iostream>
#include?<stdlib.h>
using?namespace?std;
????namespace?myNum????????????//這里想要用戶輸入一個數值并判斷是奇數還是偶數
?int?main();
{
cout?<<?"請輸入一個數值"?<<?endl;
????//???bool????isOdd,?????
????bool?isFlag?=?false;???????
if(myNum::x?%?2?==?0)
{
//???????,???false
????isFlag?=?false;
}
else
{
????//???????,???true
????isFlag?=?true;
}
????//????????
cin?>>?myNum::x;
if(isFlag?==?true)
{
//?????????true,?????x???
????cout?<<?"x?is?odd"?<<?endl;
}
else
{
????????//?????????false,?????x???
cout?<<?"x?is?even"?<<?endl;
}
return?0;
}
2016-12-14
#include <iostream>
#include <stdlib.h>
using namespace std;
namespace myNum ? ? ? ? ? ?//這里想要用戶輸入一個數值并判斷是奇數還是偶數
{
bool ?isOddOrEven() ?//做了一個bool 類型的返回值
{
int x =0;
cin >> x;
if(x % 2 == 0)// 判斷輸入的數是奇數還是偶數
{
return false; //偶數返回false
}
else
{
return true; ?//奇數返回 true
}
}
}
int main()?
{
? ? cout << "請輸入一個數值" << endl;?
? ? if(myNum::isOddOrEven())//判斷返回的bool 是 true 還是false
? ? { ? ? ?
cout << "x is odd" << endl; //返回true 為 奇數
? ? }
? ? else
? ? {
cout << "x is even" << endl; //返回 false 為偶數
? ? }
? ? return 0;
}
2017-03-07
#include<iostream>
#include<stdlib.h>
using namespace std;
namespace mynum
{
int fun()
{
int x=0;
cout<<"請輸入一個整數:"<<endl;
cin>>x;
return x;
}
}
int main ()
{
bool isflag =false;
int y=0;
y=mynum::fun();
if(y%2==0)
{
isflag=true;
}
else
{
isflag=false;
}
if(isflag)
{
cout<<"x是個偶數"<<endl;
}
else
{
cout<<"x是個奇數"<<endl;
? ? }
system("pause");
return 0;
}
2016-12-13
我調試不出來