台灣最大程式設計社群網站
線上人數
918
 
會員總數:244117
討論主題:188481
歡迎您免費加入會員
討論區列表 >> C/C++ >> 執行出來一直是0
[]  
[我要回覆]
1
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
執行出來一直是0
價值 : 20 QP  點閱數:299 回應數:2

樓主

Min Feng Hsieh
門外漢
0 1
11 1
發送站內信

#include <iostream>
#include <iomanip>
using namespace std;

const int NUMBER_QUIZZLES = 5;
const int MAX_STUDENTS = 10;

void readStudentGrades(int studentGrades[][NUMBER_QUIZZLES], int& numberStudents);
void displaySemesterGrades(double semesterGrades[], int numberStudents);
void setCoutPrecision(int numberPrecision);

void semesterGradeCounter(double semesterGrades[], int numberStudents,int studentGrades[][NUMBER_QUIZZLES]);

int main()
{
int numberStudents;
int studentGrades[MAX_STUDENTS][NUMBER_QUIZZLES];
readStudentGrades(studentGrades, numberStudents);

double semesterGrades[MAX_STUDENTS] = {0};
double median;

int i=0,j=0,temp=0;
for(i=0;i<numberStudents;i++)
{
for(j=1;j<5;j++)
{
if(semesterGrades[i]>semesterGrades[i+1])
{
temp=semesterGrades[i+1];
semesterGrades[i+1]=semesterGrades[i];
semesterGrades[i]=temp;
}
}
}

if (numberStudents%2==0)
{
median=(semesterGrades[numberStudents/2]+semesterGrades[(numberStudents/2)-1])/2;
}
else
{
median=semesterGrades[(numberStudents-1)/2];
}

setCoutPrecision(1);
displaySemesterGrades(semesterGrades, numberStudents);
cout << "Median of Semester Grades: " << median << endl;

return 0;
}

int i=0,j=0,k=0,temp=0;
double finalScore=0;

void semesterGradeCounter(double semesterGrades[], int numberStudents,int studentGrades[][NUMBER_QUIZZLES])
{
for(i=0;i<numberStudents;i++)
{
for(j=1;j<5;j++)
{
for(k=1;k<5;k++)
{
if(studentGrades[i][j]>studentGrades[i][j+1])
{
temp=studentGrades[i][j+1];
studentGrades[i][j+1]=studentGrades[i][j];
studentGrades[i][j]=temp;
}
}

}
}

for(i=0;i<numberStudents;i++)
{
finalScore=(studentGrades[i][3]+studentGrades[i][4]+studentGrades[i][5])/3;
semesterGrades[i]=finalScore;
}
}

void readStudentGrades(int studentGrades[][NUMBER_QUIZZLES], int& numberStudents)
{
cout << "Enter the number of students: ";
cin >> numberStudents;
cout << "Enter the scores for each student: ";
for (int i = 0; i < numberStudents; ++i)
{
for (int j = 0; j < NUMBER_QUIZZLES; ++j)
{
cin >> studentGrades[i][j];

}

}

}

void displaySemesterGrades(double semesterGrades[], int numberStudents)
{
cout << "Table of Semester Grades:" << endl;
for (int i = 0; i < numberStudents; ++i)
cout << setw(6) << "Stud" << i+1;
cout << endl;
for (int i = 0; i < numberStudents; ++i)
cout << setw(7) << semesterGrades[i];
cout << endl;
}

void setCoutPrecision(int numberPrecision)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(numberPrecision);
}

執行出來一直是0,哪裡錯了?
題目是要輸入學生人數及5個分數,算最高的3個分數的平均及中位數
求求各位大神幫忙解惑




搜尋相關Tags的文章: [ c++ ] ,
本篇文章發表於2018-10-21 19:44
別忘捐VP感謝幫助你的人 新手會員瞧一瞧
1樓
作者回應

Min Feng Hsieh
檢舉此回應
增加到50點求解 明天要交作業了 拜託
本篇文章回覆於2018-10-21 21:17
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
2樓
回應

Raymond
檢舉此回應
在你的 main() 裡, 所有的計算都是以 semesterGrades[] 裡的資料為主, 但你除了在定義這個陣列時把它們初始為 0 外, 你從來就沒有把 studentGrades[][] 裡的值給它們, 所以根本無從計算起.

你用 debugger 去逐行執行就可以看得出來了.

本篇文章回覆於2018-10-24 22:08
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
   
1

回覆
如要回應,請先登入.