qfedu-cpp-level/day2/d3.cpp

23 lines
411 B
C++
Raw Permalink Normal View History

#include <iostream>
using namespace std;
// 引用传递: 会改变实参的值
// 值传递: 不会改变实参的值
void cumsum(int &total, int n) // total 是引用传递n 是值传递
{
total += n;
}
int main()
{
int total = 0;
int n = 0;
while (cin >> n)
{
cumsum(total, n);
cout << "total = " << total << endl;
if (total > 100)
break;
}
}