/*
* Brian Todd
* CSC 160-001
* Project 5 - In nums
* Description: Takes in numbers and outputs min, max and average.
*/
#include
int main()
{
double in = 0;
double max = 0;
double min = 10000000; //..hopefully, this won't be less than the user's smallest input ;)
double sum = 0;
double count = 0;
while(in != -1)
{
cout << "Please enter a number: ";
cin >> in;
if (in != -1)
{
count++;
sum = sum + in; //...or write: sum += in;
if (in > max)
{
max = in;
}
else
if( in < min )
{
min = in;
}
}
}
//...a divide by zero will crash your program, so...
if(sum == 0) sum = 1;
if(count == 0) count = 1;
cout << "The maximum value was: " << max << endl;
cout << "The minimum value was: " << min << endl;
cout << "The average of all values is: " << (sum / count) << endl;
return 0;
}