访客只能看到部份内容,免费 加入会员 或由脸书 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; }