返回列表 發帖

基本輸入輸出

本帖最後由 鄭繼威 於 2022-4-18 20:16 編輯


cout 輸出<-------->cin 輸入
cout<<x; 輸出x
cin>>x; 輸入x
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a;   //int ---> integer  整數
  7.     cout<<"請輸入一整數: ";
  8.     cin>>a;
  9.     cout<<"你剛輸入的數字是: "<<a<<endl;
  10.     system("pause");
  11.     return 0;   
  12. }
複製代碼

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a;   //int ---> integer  整數
  7.     cout<<"請輸入一整數: ";
  8.     cin>>a;
  9.     cout<<"你剛輸入的數字是: "<<a<<endl;
  10.     system("pause");
  11.     return 0;   
  12. }
複製代碼

TOP

本帖最後由 黃裕恩 於 2022-3-16 20:42 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a;   
  7.     cout<<"請輸入一整數: ";
  8.     cin>>a;
  9.     cout<<"你剛輸入的數字是: "<<a<<endl;
  10.     system("pause");
  11.     return 0;   
  12. }
複製代碼

TOP

本帖最後由 陳牧謙 於 2022-3-16 20:43 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a;
  7.     cout<<"請輸入一個整數: ";
  8.     cin>>a;
  9.     cout<<"你剛輸入的數字是:"<<a<<endl;

  10.     system("pause");
  11.     return 0;
  12. }   
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a;
  7.     cout<<"請輸入一整數: ";
  8.     cin>>a;
  9.     cout<<"你剛輸入的數字是: "<<a<<endl;
  10.     system("pause");
  11.     return 0;   
  12. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;

  4. int main(){
  5.    
  6.     //宣告變數
  7.     //變數型態 變數名稱(=賦予值)
  8.     int score;
  9.     cout<<"請輸入成績:";
  10.     cin>>score;
  11.    
  12.     //開始判斷
  13.     //分數=100
  14.     if(score==100){
  15.          cout<<"滿分"<<endl;     
  16.     }
  17.     //60~99 -> 60<=score<100
  18.     else if(score>=60 && score<100){
  19.          cout<<"好高分"<<score<<endl;     
  20.     }
  21.     //1~59 -> 0<=score<60
  22.     else if(score>=1 && score<60){
  23.          cout<<"不及格,你的分數:"<<score<<endl;   
  24.     }
  25.     //score=0
  26.     else if(score==0){
  27.          cout<<"零分"<<endl;     
  28.     }
  29.     //其他狀況 0~100以外
  30.     else{
  31.          cout<<"輸入錯誤"<<endl;
  32.     }
  33.    
  34.     system("pause");             //黑色畫面暫停
  35.     return 0;                    //告知主程式已完成
  36. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;

  4. int main(){
  5.     //你要做的事
  6.     //宣告變數
  7.     //變數型態 變數名稱=賦予值
  8.     int a;
  9.     cout<<"請輸入一個整數:";
  10.     cin>>a;
  11.     cout<<"a的內容為:"<<a<<endl;
  12.    
  13.     system("pause");
  14.     return 0;   
  15. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      int a;   
  7.     cout<<"請輸入一整數:";
  8.     cin>>a;
  9.     cout<<"a的內容為: "<<a<<endl;
  10.     system("pause");
  11.     return 0;
  12. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>

  3. using namespace std;  
  4. int main()
  5. {
  6.    
  7. int a;   
  8.     cout<<"請輸入一整數: ";
  9.     cin>>a;
  10.     cout<<"你剛輸入的數字是: "<<a<<endl;
  11.    
  12.    
  13.     system("pause");
  14.     return 0;
  15.    
  16. }
複製代碼

TOP

返回列表