- #include<iostream> // <-基本輸出輸入的函式庫 Input Output cin 輸入 cout 輸出
- #include<cstdlib> //主要的函式庫 Library
- using namespace std;
- int main()
- {
- int x; int y;
- cout << "兩數的五則運算" <<endl;
- cout << "請輸入x的值:" <<endl;
- cin >> x;
- cout << "請輸入y的值:" <<endl;
- cin >> y;
-
-
-
-
- //正 正 = > 正
- //正 負 = > 負
- //負 正 = >負
- //負 負 = > 正
-
-
- // && and = > 兩者都要成立就回傳true
- // || or = > 兩者只要其中一者成立就回傳true
- // ! = > false
- // 1 true 0 false
- if(x!=0 && y!=0)//判斷條件是否符合 if內的判斷式如果成立就做括號內的事
- {
- //如果if內的條件不成立 就做else內括號的事
- cout << "x+y=" << x+y << endl;
- cout << "x-y=" << x-y << endl;
- cout << "x*y=" << x*y << endl;
- cout << "x/y=" << x/y << endl;
- cout << "x%y=" << x%y << endl;
- }
- else{
- cout << "x與y的值不可以為0 請重新輸入!" << endl;
-
- }
-
-
- system("pause");
- return 0;
- }
複製代碼 |