# 20191017 基礎班 --- ## 作業參考解答 ```cpp #include<iostream> using namespace std; int main() { cout << "請輸入分數:"; int grade; cin >> grade; if (grade == 100) { cout << "A+"; } else if (grade >= 90) { cout << "A"; } else if (grade >= 80) { cout << "B"; } else if (grade >= 70) { cout << "C"; } else if (grade >= 60) { cout << "D"; } else { cout << "F"; } } ``` --- ## 今日重點 --- ### while ![](https://cs50.harvard.edu/ap/curriculum/1/notes/forever.png) ```cpp while (true) { cout << "hello, world\n"; } ``` --- ### for ![](https://cs50.harvard.edu/ap/curriculum/1/notes/repeat.png) ```cpp for (int i = 0; i < 50; i++) { cout << "hello, world\n"; } ``` --- ### 輸入字串 ![](https://cs50.harvard.edu/ap/curriculum/1/notes/ask_say.png) ```cpp cout << "What's your name?" string answer; cin >> answer; cout << answer; ``` ---- ### 輸入字串 2 ![](https://cs50.harvard.edu/ap/curriculum/1/notes/ask_say_join.png) ```cpp cout << "What's your name?" string answer; cin >> answer; cout << "hello, " << answer; ``` --- ## GitHub https://github.com --- # 課後新增 --- ## Telegram * 頻道 https://t.me/nssh_cs * 群組 https://t.me/joinchat/DA68DxcYVqR7oh2hhCcmhg --- ## 以下程式碼區塊差異在哪? 想想看,會有幾個 `cout`,又顯示了什麼? ---- ### Code block 1 ```cpp int main() { for (int times = 0; times < 5; times++) { cout << "times 現在的值是:" << times; } } ``` ---- ### Code block 2 ```cpp int main() { for (int times = 1; times <= 5; times++) { cout << "times 現在的值是:" << times; } } ``` ---- ### Code block 3 ```cpp int main() { int times = 10; for (int times = 0; times < 5; times++) { cout << "times 現在的值是:" << times; } cout << "times 現在的值是:" << times; } ``` ---- ### Code block 4 ```cpp int main() { int times = 10; for (times = 0; times < 5; times++) { cout << "times 現在的值是:" << times; } cout << "times 現在的值是:" << times; } ``` --- ## 下禮拜(2019/10/24)考試 * `cout` / `cin` * `int` * `if` / `else if` / `else` * `while` * `for` * `string`
{"metaMigratedAt":"2023-06-15T00:51:28.763Z","metaMigratedFrom":"Content","title":"20191017 基礎班","breaks":true,"contributors":"[{\"id\":\"39811bc9-1305-4534-84c5-a4c97d2ac539\",\"add\":2150,\"del\":29}]"}
    815 views
   Owned this note