返回列表 發帖

if...else if...else 敘述

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int x, y;
  6.     cout<<"請輸入x: ";
  7.     cin>>x;
  8.     cout<<"請輸入y: ";
  9.     cin>>y;
  10.     cout<<"您剛輸入的x為"<<x<<", y為"<<y<<endl;
  11.     if(x>y)                        //符合什麼條件
  12.     {                              //做什麼動作
  13.         cout<<"x大於y!"<<endl;
  14.     }
  15.     else if(x<y)
  16.     {
  17.         cout<<"x小於y!"<<endl;
  18.     }
  19.     else
  20.     {
  21.         cout<<"x等於y!"<<endl;
  22.     }
  23.     system("pause");
  24.     return 0;
  25. }
複製代碼

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.   int x;
  6.   int y;
  7.   cout<<"請輸入x"<<endl;
  8.   cin>>x;
  9.   cout<<"請輸入y"<<endl;
  10.   cin>>y;
  11.   cout<<"您輸入的x為"<<x<<",y為"<<y<<endl;
  12.   if(x>y)
  13.   {
  14.   cout<<"x大於Y"<<endl;
  15.   }
  16.   else if(x<y)
  17.   {
  18.    cout<<"x小於Y"<<endl;   
  19.   }
  20.   else
  21.   {
  22.   cout<<"x等於y"<<endl;   
  23.   }
  24.   system("pause");
  25.   return 0;      
  26. }
複製代碼

TOP

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.   int x, y;
  6.   cout<<"請輸入x:"<<endl;
  7.   cin>>x;
  8.   cout<<"請輸入y:"<<endl;
  9.   cin>>y;
  10.   cout<<"您剛輸入x為"<<x<<",y為"<<y<<endl;
  11.   if(x>y)
  12.   {
  13.     cout<<"x大於y"<<endl;
  14.   }
  15.   else if(x<y)
  16.   {
  17.       cout<<"x小於y"<<endl;
  18.   }
  19.   else
  20.   {
  21.        cout<<"x等於y"<<endl;
  22.   }
  23.    system("pause");
  24.    return 0;  
  25. }
複製代碼

TOP

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int x, y;
  6.     cout<<"請輸入x:";
  7.     cin>>x;
  8.     cout<<"請輸入y:";
  9.     cin>>y;
  10.     cout<<"您剛輸入的x為:"<<x<<"您剛輸入的y為:"<<y<<endl;
  11.     if(x>y)
  12.     {
  13.          cout<<"x大於y"<<endl;
  14.     }
  15.      else if(x<y)     
  16.     {
  17.          cout<<"x小於y"<<endl;
  18.     }
  19.      else
  20.     {
  21.          cout<<"x等於y"<<endl;   
  22.     }
  23.     system("pause");
  24.     return 0;
  25. }
複製代碼

TOP

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.       cout<<"☆☆☆☆☆☆☆☆☆" <<endl;
  6.       float x, y;
  7.       cout<<"☆請輸入X:";
  8.       cin>>x;
  9.       cout<<"☆請輸入Y:";
  10.       cin>>y;
  11.       cout<<"☆你輸入的X為"<<x<<",Y為"<<y<<endl;
  12.       if(x>y)
  13.       {
  14.              cout<<"☆X大於Y"<<endl;
  15.       }
  16.       else if(x<y)
  17.       {
  18.              cout<<"☆X小於Y"<<endl;
  19.       }
  20.       else
  21.       {
  22.              cout<<"☆X等於Y"<<endl;
  23.       }
  24.       cout<<"☆☆☆☆☆☆☆☆☆"<<endl ;
  25.       
  26.       
  27.       system("pause");
  28.       return 0;
  29.       
  30. }
複製代碼

TOP

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int x, y;
  6.     cout<<"請輸入x: ";
  7.     cin>>x;
  8.     cout<<"請輸入y: ";
  9.     cin>>y;
  10.     cout<<"您剛輸入的x為"<<x<<", y為"<<y<<endl;
  11.     if(x>y)                        
  12.     {                              
  13.         cout<<x<<"大於"<<y<<"!"<<endl;
  14.     }
  15.     else if(x<y)
  16.     {
  17.         cout<<x<<"小於"<<y<<"!"<<endl;
  18.     }
  19.     else
  20.     {
  21.         cout<<x<<"等於"<<y<<"!"<<endl;
  22.     }
  23.     system("pause");
  24.     return 0;
  25. }
複製代碼

TOP

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.   int x;
  6.   int y;
  7.   cout<<"請輸入X:"<<endl;
  8.   cin>>x;
  9.   cout<<"請輸入y:"<<endl;
  10.   cin>>y;
  11.   
  12.   cout<<"您輸入的x為:"<<x<<endl;
  13.   cout<<"您輸入的y為:"<<y<<endl;
  14.   
  15.   if(x>y)
  16.   {
  17.      cout<<"x大於y"<<endl;     
  18.    }
  19.   else if(x<y)
  20.   {
  21.     cout<<"x小於y"<<endl;   
  22.   }
  23.   else
  24.   {
  25.     cout<<"x等於y"<<endl;  
  26.   }
  27.   
  28.   system("pause");
  29.   return 0;   
  30.    
  31. }
複製代碼

TOP

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int x, y;
  6.     cout<<"請輸入x: ";
  7.     cin>>x;
  8.     cout<<"請輸入y: ";
  9.     cin>>y;
  10.     cout<<"您輸入的x為"<<x<<", y為"<<y<<endl;
  11.     if(x>y)
  12.     {
  13.         cout<<"x 大於 y"<<endl;   
  14.     }else if(x<y)
  15.     {
  16.         cout<<"x 小於 y"<<endl;
  17.     }else
  18.     {
  19.         cout<<"x 等於 y"<<endl;
  20.     }
  21.     system("pause");
  22.     return 0;   
  23. }
複製代碼

TOP

返回列表