// C5_1.cpp : Defines the entry point for the console application. // 陣列的應用 #include "stdafx.h" #include #include using namespace std; int main(int argc, char* argv[]) { const int MAX = 20; // 設定最大值 double idnum[ MAX ]; // 宣告陣列變數 long score[ MAX ]; int count = 0; char indicator = 'y'; while( (indicator == 'y' || indicator == 'Y') && count < MAX ) { cout << endl << "請輸入學生編號 : "; cin >> idnum[count]; // 讀取學生編號 cout << "請輸入分數 : "; cin >> score[count]; // 輸入分數 ++count; cout << "是否要輸入其他記錄 (y or n)? "; cin >> indicator; } if(count <= 1) { cout << endl << "請最少輸入二筆資料!"; return 0; } // 輸出結果值 for(int i=0; i < count; i++) cout << endl << setw(2) << i << "." //輸出序列值 << "學生編號 = " << idnum[ i] // 輸出編號 << " 分數為 " << score[i] << " 分."; cout << endl; return 0; }