【发布时间】:2018-12-12 21:02:51
【问题描述】:
我正在尝试编写一个程序,将学生的最后分数计算为期中、测验1、测验2 和期末,然后发现他们的班级平均成绩取决于学生人数。程序将显示班级平均水平。用户应输入分数。我是 C++ 新手,我的问题是现在我找不到将这个 for 循环连接到类平均值数组的方法。我的代码错了吗?我不知道该怎么办。
#include <iostream>
using namespace std;
int main()
{
int mt, q1, q2, fnl, stdn, num;
double cls[5], std, avg;
cout << "Enter a number of students: ";
cin >> num;
for (stdn=0; stdn<num; stdn++) {
cout<<"Enter mt, q1, q2, fnl of a "<<stdn+1<<". student in order:"<<endl;
cin>>mt>>q1>>q2>>fnl;
std = mt * 30/100 + q1 * 10/100 + q2 * 10/100 + fnl * 50/100;
cout<<stdn+1<<". students total score is "<<std<<endl;
}
}
【问题讨论】:
-
您的代码很可能遭受整数除法的影响。
-
请注意,这与 Joy Division 完全不同。