| |
/* Given that only positive numbers are entered, this program computes and
outputs the average, maximum, and minimum. -1 signifies the end of the input.*/
#include <iostream.h>
#include <conio.h>
main()
{
int input = 0;
int divide = 0;
int number;
int max = 0;
int min = 1000;
float average, total;
cout <<"Enter numbers you wish to average \nWhen you are done type -1.";
while (input != -1)
{
total += input;
divide++;
cout <<endl <<"Enter a number: ";
cin >> input;
if(input >= max)
max = input;
if(input <= min)
{
if(input != -1)
min = input;
}
else
min = min;
}
--divide;
average = total / divide;
cout <<endl <<"The average is " <<average;
cout <<endl <<"The max. number entered was: " <<max;
cout <<endl <<"The min. number entered was: " <<min;
getch();
} |