返回列表 發帖

五則運算(三)

  1. #include<iostream> // <-基本輸出輸入的函式庫 Input Output   cin 輸入 cout 輸出  
  2. #include<cstdlib> //主要的函式庫 Library
  3. using namespace std;
  4. int main()
  5. {
  6.     int x; int y;
  7.     cout << "兩數的五則運算" <<endl;
  8.     cout << "請輸入x的值:" <<endl;
  9.     cin >> x;
  10.     cout << "請輸入y的值:" <<endl;
  11.     cin >> y;
  12.    
  13.     // 1 true 0 false
  14.     if(y==0)//判斷條件是否符合  if內的判斷式如果成立就做括號內的事
  15.     {
  16.         cout << "y的值不可以為0 請重新輸入!" << endl;
  17.     }
  18.     else{ //如果不成立 就做else內括號的事
  19.          cout << "x+y=" << x+y << endl;
  20.          cout << "x-y=" << x-y << endl;
  21.          cout << "x*y=" << x*y << endl;
  22.          cout << "x/y=" << x/y << endl;
  23.          cout << "x%y=" << x%y << endl;
  24.     }
  25.    

  26.     system("pause");  
  27.     return 0;  
  28. }
複製代碼

返回列表