use*_*101 0 c++ for-loop function
好的,所有传递给这个函数的数字作为参数,都返回正确的值,我无法弄清楚为什么在我运行之后我得到一些荒谬的数字作为标准偏差.即我得到的数字是(4.23947e10)或沿着那些线的东西,并且显示功能正在跳过每隔一行.
float stdDev(int arrayList [], int count, float average)
{
int deviation;
int sum2 = 0;
for (int i = 0; i <= count; i++)
{
sum2 += pow((arrayList[i] - average), 2);
}
deviation = sqrt(sum2 / (count - 1));
return deviation;
}
void displayList(int heightlist [], int weightlist[], int count)
//displays list of integers based on lists
{
cout << "\tHeight(s)" << " " << "Weight(s)" << endl;
for (int i = 0; i <= count; i++)
{
cout << "\t[" << heightlist[i] << "]" << " " << "["<< weightlist[i] <<"]" << '\n';
i++;
}
}
Run Code Online (Sandbox Code Playgroud)
我觉得你太过分了:
for (int i = 0; i <= count; i++)
// ^^
Run Code Online (Sandbox Code Playgroud)
可能意味着i < count.
也:
int deviation;
int sum2 = 0;
Run Code Online (Sandbox Code Playgroud)
你的意思是float deviation, sum2?
| 归档时间: |
|
| 查看次数: |
1103 次 |
| 最近记录: |