返回列表 發帖

自我介紹

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

試宣告五個變數來裝你的個人資料, 分別為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. using namespace std;

  3. int main(){
  4.         //整數 int 10,50,100..
  5.         //浮點數(小數) float 3.14...
  6.         //字元 char 'a','b','@'
  7.         //字串 string "abcdefg","apple"
  8.        
  9.         //宣告變數(盒子)
  10.         //變數型態 變數名字=賦予值
  11.         string name="鄭繼威";
  12.         string school="資培會";
  13.         int age=25;
  14.         float h=180,w=56;
  15.        
  16.         int apple=500;

  17.         //cout輸出 <<串接符號(當方法、變數、字串要一起使用) endl換行
  18.         cout<<"我的名字:"<<name<<endl;
  19.         cout<<"我的學校:"<<school<<endl;
  20.         cout<<"我的年紀:"<<age<<endl;
  21.         cout<<"我的身高:"<<h<<endl;
  22.         cout<<"我的體重:"<<w<<endl;

  23.         cout<<apple<<endl;

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

TOP

返回列表