我有一个练习,我应该输入多个以零结束的数字,然后对它们执行不同的计算。到目前为止,我创建了一个do..while
用于存储数字的循环。我被告知,如果没有阵列,这是可能的,如果那是错的,请马上告诉我。我需要做的功能是将所有数字相加,找到最高数字和第二高数字,以及所有数字的中间(平均)值。 我认为我应该使用不同的库,也可能有不同的选项。 请帮我理解不同的库以及如何使用它们。 我在网上找到的搜索结果没有给我我找到的答案,因为我找不到类似的问题。 这是我到目前为止的代码:需要多个数字并执行不同作业的C++函数
#include<iostream>
#include<string>
using namespace std;
int sumCalc (int);
int midValCalc (int);
int secHighCalc (int);
int highestCalc (int);
void printCalc();
int main() {
int nums;
cout << "Input numbers, quit with 0: ";
do {
cin >> nums;
cout << nums << " "; // This is just to see the result
}
while (nums != 0);
return 0;
}
什么是错的这个附加功能?
int sumCalc (int total) {
total = 0;
while (nums != 0) {
total += nums;
}
return nums;
}
当你说“中等价值”是指你的中位数还是平均值? – Beta
我确实希望没有人提供完整的解决方案,坦率地说,从长远来看,这根本无助于OP。 – PeterK
对不起,是这个意思。 – Sociopaten