7iii.cpp

来自「C/C++程序设计导论(第二版)》程序源文件」· C++ 代码 · 共 20 行

CPP
20
字号
#include <iostream.h>
// AverageInput3 ()  Input positive values until a negative
// sentinel value is encounter. Return the average.
//  ASSUMPTION: at least one value is entered.
//  OUT:  count -- the number of values averaged
float AverageInput3 (int& count)
{	float sum = 0.0, value;
	cin >> value;
	for (count=0; value > 0.0; count=count+1)
	{	sum = sum + value;
		cin >> value;
	}
	return (sum / count);
}
void main ()
 { int n;
	cout << AverageInput3 (n);
	cout << n << endl;
 }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?