You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
403 B
C++
29 lines
403 B
C++
5 years ago
|
Average function
|
||
|
|
||
|
#include <iostream>
|
||
|
#include <stdlib.h>
|
||
|
int Average(int i)
|
||
|
{
|
||
|
static int sum = 0, count = 0;
|
||
|
sum = sum + i;
|
||
|
count++;
|
||
|
return sum / count;
|
||
|
}
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
|
||
|
int num;
|
||
|
do{
|
||
|
|
||
|
cout<<"Enter numbers ( -1 to quit )"<<endl;
|
||
|
cin>>num;
|
||
|
/*if number is not -1 print the average*/
|
||
|
if(num != -1)
|
||
|
cout<<"The average is "<<Average(num)<<endl;
|
||
|
|
||
|
|
||
|
}while(num>-1);
|
||
|
return 0;
|
||
|
}
|