訪客只能看到部份內容,免費 加入會員 或由臉書 Google 可以看到全部內容
下面是引用 vwmn123 於 2009-02-04 20:39 發表的 : 原來我第二個FOR設定不一樣,難怪會當機,再請問大大 a_total=0,一定要宣告初始值嗎?
a_total+=a[o];
#include <iostream> using namespace std; const int m_max = 10; int main(int argc, char* argv[]) { int i ; int CH[m_max]={0}, EN[m_max]={0}, MA[m_max]={0}; int CH_SUM = 0, EN_SUM = 0, MA_SUM = 0; double CH_AVG=0.0, EN_AVG=0.0, MA_AVG=0.0; int Total[m_max]={0}; double Total_AVG[m_max]={0.0}; int AVG_SUM = 0 ; double ALL_AVG = 0.0; for(i=0;i<m_max;i++){ cin>>CH[i]>>EN[i]>>MA[i]; Total[i] = CH[i]+EN[i]+MA[i] ; Total_AVG[i] = ((double)Total[i]) / 3 ; } cout<<"==============================================="<<endl; for(i=0;i<m_max;i++){ cout<<"學號 "<<i+1 <<" 國文 "<<CH[i]<<" 英文 "<<EN[i]<<" 數學 "<<MA[i] <<" 總合 "<<Total[i]<<" 平均 "<<Total_AVG[i]<<endl; } for(i=0;i<m_max;i++){ CH_SUM += CH[i] ; EN_SUM += EN[i] ; MA_SUM += MA[i] ; } CH_AVG = ((double)CH_SUM) / m_max ; EN_AVG = ((double)EN_SUM) / m_max ; MA_AVG = ((double)MA_SUM) / m_max ; AVG_SUM = CH_AVG + EN_AVG + MA_AVG ; ALL_AVG = ((double)AVG_SUM) / 3 ; cout<<"==============================================="<<endl; cout<<"國文總平均: "<<CH_AVG<<endl; cout<<"英文總平均: "<<EN_AVG<<endl; cout<<"數學總平均: "<<MA_AVG<<endl; cout<<"總分(平均): "<<AVG_SUM<<endl; cout<<"總平均: "<<ALL_AVG<<endl; system("pause"); return 0; }