C++函数,它接受多个数字并执行不同的作业

Soc*_*ten 2 c++ function operation

我有一个练习,我应该输入多个以零结束的数字,然后用它们执行不同的计算.到目前为止,我已经创建了一个do..while用于存储数字的-loop.有人告诉我这可能没有阵列,如果有错,请马上告诉我.我需要做的功能是将所有数字加在一起,找到最高数字和第二高数字,以及所有数字的中间(平均)值.我认为我应该使用不同的库,也可能有不同的选项.请帮助我了解不同的库以及如何使用它们.我在网上找到的搜索结果并没有给我我想要的答案,因为我找不到类似的问题.到目前为止这是我的代码:

#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;
}
Run Code Online (Sandbox Code Playgroud)

这个添加功能有什么问题?

int sumCalc (int total)   {

total = 0;
while (nums != 0) {
    total += nums;
}

return nums;
Run Code Online (Sandbox Code Playgroud)

}

Jon*_*sky 5

我认为你不需要任何不寻常的库.

想想你如何在精神上计算这些东西.例如,如果您要将我读过的数字列表相加,您只需跟踪运行总数,并在添加数字时忘记每个数字 - 这样只需要一个变量.如果你想跟踪输入的最大数字,你只需记住你到目前为止看到的最大数字,并在你得到它们时比较新数字.

你可以解决这些问题.