024.程式流程結構-選擇結構-多行if語句
阿新 • • 發佈:2021-09-03
#include <iostream> using namespace std; int main() { //選擇結構 單行if語句 //使用者輸入分數,如果分數大於600,視為考上一本大學,在螢幕上輸出 //1.使用者輸入分數 int scroe = 0; cout << "請輸入一個分數:" << endl; cin >> scroe; //2.列印使用者輸入的分數; cout << "你輸入的分數是:" << scroe << endl; //3.判斷分數是否大於600,如果大於600,輸出//注意事項,if條件後面不要加分號; if (scroe > 600) { if (scroe>700) { cout << "你考上北大" << endl; } else if (scroe>650) { cout << "你考上清華" << endl; } else { cout << "你考上人大" << endl; } }else if (scroe > 500) { cout << "你考上的是二本大學" << endl; } else if (scroe > 400) { cout << "你考上的是三本大學" << endl; } else { cout << "你未考上的大學" << endl; } system("pause"); return 0; }