📄 5ii.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 + -