⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 5ii.cpp

📁 《C/C++程序设计导论(第二版)》一书的程序源文件
💻 CPP
字号:
#include <iostream.h>

// GetAveMaxMin()  Calculate the average, max, and min. of
// a list of pos. values terminating with a negative number
// ASSUMPTION: List must contain one positive value
//	OUT: 		max, min will be the list maximum & minimums
//	Returns: The average of the list

float GetAveMaxMin (float& max, float& min)
{ 	float sum, count, value;
	sum = 0.0;
	count = 0.0;
	cin >> value;					// get the first value
	max = value;
	min = value;					// assume it is both the max and min
	while (value > 0.0)					// check for sentinel
	{	sum = sum + value;
		count = count + 1.0;				// sum and count values in loop...
		if (value > max)				// compare against previous
			max = value;			//   assumptions for max and min..
		if (value < min)				//  (and change if needed)
			min = value;
		cin >> value;
	}
	return (sum / count);					// calculate and return average
}

void main ()
 { float ave, max, min;
	ave = GetAveMaxMin (max, min);
	cout << ave << " " << max << " " << min << endl;
 }

⌨️ 快捷键说明

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