返回列表 發帖

自我介紹

宣告變數語法  ->  變數型態 變數名字=賦予值

試宣告五個變數來裝你的個人資料, 分別為2個字串(string)變數, 1個整數(int)變數, 2個浮點數(float)變數, 完成如下的執行畫面:

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string name="黃國穎", school="愛國國小";
  7.     int age=9;
  8.     float h=138.6, w=27.5;
  9.     cout<<"我的大名: "<<name<<endl;
  10.     cout<<"就讀: "<<school<<endl;
  11.     cout<<"今年: "<<age<<" 歲"<<endl;
  12.     cout<<"身高: "<<h<<" 公分"<<endl;
  13.     cout<<"體重: "<<w<<" 公斤"<<endl;
  14.     system("pause");
  15.     return 0;   
  16. }
複製代碼

  1. #include<iostream>//引入基本輸入輸出函式庫
  2. #include<cstdlib>
  3. using namespace std;

  4. int main(){
  5. //        ...
  6. //int 整數 ex:1 2 3 ....
  7. //float 浮點數(小數) ex:1.2 2.3 3.5 3.14
  8. //string 字串 ex:"apple","bee","cat"
  9. //char 字元 ex:'a','p','p','l','e'
  10. //bool 布林 ex:0(false),1(true)
  11. //        變數型態 變數名字=賦予值
  12. //        string name="鄭繼威";
  13. //        string school="資培會";
  14.        
  15.         string name="鄭繼威",school="資培會";
  16.         int age=25;
  17.         float h=180,w=60;
  18.         //cout<< 輸出 cin輸入>>
  19.         cout<<"我的大名:"<<name<<endl;
  20.         cout<<"我的學校:"<<school<<endl;
  21.         cout<<"我的年紀:"<<age<<endl;
  22.         cout<<"我的身高:"<<h<<"cm"<<endl;
  23.         cout<<"我的體重:"<<w<<"kg"<<endl;
  24.        
  25.         system("pause");
  26.         return 0;
  27. }
複製代碼

TOP

返回列表