我为我的课堂写了一个练习程序,除了返回变量的值外,所有程序都可以正常工作。我的问题是,为什么它不返回值?这是我写的示例代码,以避免必须复制和粘贴不相关的大部分代码。
#include <iostream>
using std::cout; using std::cin;
using std::endl; using std::fixed;
#include <iomanip>
using std::setw; using std::setprecision;
int testing();
int main()
{
testing();
return 0;
}
int testing() {
int debtArray[] = {4,5,6,7,9,};
int total = 0;
for(int debt = 0; debt < 5; debt++) {
total += debtArray[debt];
}
return total;
}
实际上,该函数正在返回一个值。但是,main()
选择忽略该返回值。
在您的中尝试以下操作main()
:
int total = testing();
std::cout << "The total is " << total << std::endl;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句