返回列表 發帖

[練習] if...else ~~(驚嘆號,true,false)

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {

  6.    
  7.     //  5>4 正確的 true 跑上面的結果   3<4 錯誤的 false 跑下面的結果
  8.     if(!true) // 加了一個驚嘆號 變成反向結果
  9.     {
  10.         cout<<"true"<<endl;
  11.     }else
  12.     {
  13.         cout<<"false"<<endl;
  14.     }
  15.     cout<<"============================="<<endl;
  16.    
  17.     if(120 != 120 )   // != 不等於   120 != 120   ==等於  120 ==120
  18.     {                          
  19.         cout<<"血壓正常~"<<endl;
  20.     }else
  21.     {
  22.         cout<<"血壓異常!!!"<<endl;         
  23.     }

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

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.   int a,b,c;
  7.   cin>>a;
  8.   cin>>b;
  9.   cin>>c;
  10.   if((a>100&&b<5)||c>120)  
  11.   {
  12.   cout<<"ture"<<endl;
  13.   }else
  14.   {
  15.   cout<<"false"<<endl;      
  16.   }  
  17.    
  18.    
  19.    
  20.    
  21.    
  22.    
  23.    
  24.      system("pause");   
  25.      return 0;   
  26. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {

  6.    
  7.    
  8.     if(!true)
  9.     {
  10.         cout<<"true"<<endl;
  11.     }else
  12.     {
  13.         cout<<"false"<<endl;
  14.     }
  15.     cout<<"============================="<<endl;
  16.    
  17.     if(120 != 120 )   
  18.     {                          
  19.         cout<<"血壓正常~"<<endl;
  20.     }else
  21.     {
  22.         cout<<"血壓異常!!!"<<endl;         
  23.     }

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

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     //re:
  7.     if(!!false)
  8.     {
  9.         cout<<"true"<<endl;
  10.     }else
  11.     {
  12.         cout<<"false"<<endl;
  13.     }
  14.    
  15.     if(120 == 120 )  
  16.     {                          
  17.         cout<<"正常~~~~~~~~~"<<endl;
  18.     }else
  19.     {
  20.         cout<<"*不正常呀!!"<<endl;         
  21.     }
  22.     cout<<""<<endl;
  23.       if(120 != 120 )   
  24.     {                          
  25.         cout<<"good"<<endl;
  26.     }else
  27.     {
  28.         cout<<"bad!!!"<<endl;         
  29.     }

  30.     //goto re;   
  31.     system("pause");
  32.     return 0;
  33. }
複製代碼

TOP

  1. #include<cstdlib>
  2. #include<iostream>
  3. using namespace std;
  4. int main()
  5. {
  6.    if(60>20&&30>90||60>40)
  7.    {
  8.     cout<<"正確"<<endl;
  9.    }
  10.    else
  11.    {
  12.     cout<<"不正確 "<<endl;
  13.    }
  14.    if(true&&!(30>90))
  15.    {
  16.     cout<<"正確"<<endl;
  17.    }
  18.    else
  19.    {
  20.     cout<<"不正確 "<<endl;
  21.    }
  22.    if(true&&(30>90))
  23.    {
  24.     cout<<"正確"<<endl;
  25.    }
  26.    else
  27.    {
  28.     cout<<"不正確 "<<endl;
  29.    }
  30.    if(0)
  31.    {
  32.     cout<<"正確"<<endl;
  33.    }
  34.    else
  35.    {
  36.     cout<<"不正確 "<<endl;
  37.    }
  38.    if(1&&true)
  39.    {
  40.     cout<<"正確"<<endl;
  41.    }
  42.    else
  43.    {
  44.     cout<<"不正確 "<<endl;
  45.    }
  46.    if(1&&900||6)
  47.    {
  48.     cout<<"正確"<<endl;
  49.    }
  50.    else
  51.    {
  52.     cout<<"不正確 "<<endl;
  53.    }
  54.    if(90<0&&!0)
  55.    {
  56.     cout<<"正確"<<endl;
  57.    }
  58.    else
  59.    {
  60.     cout<<"不正確 "<<endl;
  61.    }
  62.    if(!false||5<6)
  63.    {
  64.     cout<<"正確"<<endl;
  65.    }
  66.    else
  67.    {
  68.     cout<<"不正確 "<<endl;
  69.    }
  70.    if(30==9)
  71.    {
  72.     cout<<"正確"<<endl;
  73.    }
  74.    else
  75.    {
  76.     cout<<"不正確 "<<endl;
  77.    }
  78.    system("pause");
  79.    return 0 ;
  80.    
  81.    
  82. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x,y,a,b;
  7.     cout<<"請輸入收縮壓:";
  8.     cin>>x;
  9.     cout<<"請輸入舒張壓:";
  10.     cin>>y;
  11.     if(x <120 && y <80 )
  12.     {
  13.          cout<<"正常"<<endl;
  14.     }
  15.     else
  16.     {
  17.          cout<<"有問題,建議詢問醫生"<<endl;
  18.     }
  19.     if(true)
  20.     {
  21.          cout<<"......?...好像不正常?"<<endl;
  22.     }
  23.     else
  24.     {
  25.          cout<<"你很健康。"<<endl;
  26.     }
  27.      if(!true)
  28.     {
  29.          cout<<"等等!你病了!"<<endl;
  30.     }
  31.     else
  32.     {
  33.          cout<<"不對,你沒什麼問題"<<endl;
  34.     }if(false)
  35.     {
  36.          cout<<"不對,你沒什麼問題"<<endl;
  37.     }
  38.     else
  39.     {
  40.          cout<<"你病了。"<<endl;
  41.     }
  42.    
  43.     system("pause");
  44.     return 0;
  45. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a,b,c;
  7.     cout<<"Please input a number:";
  8.     cin>>a;
  9.     cout<<"Please input another number:";
  10.     cin>>b;
  11.     cout<<"Please input another number again:";
  12.     cin>>c;
  13.     if(!(a>60) && (b>60 || c>80))
  14.     {
  15.     cout<<"Great"<<endl;   
  16.     }else
  17.     {
  18.     cout<<"not great"<<endl;
  19.     }
  20.     system("pause");
  21.     return 0;
  22. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    
  7.     if(!true)
  8.     {
  9.       cout<<"良好"<<endl;               
  10.     }
  11.     else
  12.     {
  13.       cout<<"不良好"<<endl;  
  14.     }
  15.     cout<<"========================"<<endl;
  16.     if(120!=120)
  17.     {
  18.         cout<<"血壓正常~"<<endl;            
  19.     }
  20.     else
  21.     {
  22.         cout<<"血壓異常~"<<endl;
  23.     }
  24.     system("pause");
  25.     return 0;
  26. }
複製代碼

TOP

返回列表