Hi, I wrote the following program to compute a running average, but it will not compile in DEV C++. It is pretty much straight out of a c++ user guide, so I think it should work. The point of the excersise was to learn about functions and how a function is called.
/* This computer computes a running average of numbers
entered by the user */
#include <iostream>
usingnamespace std;
int r_avg(int i); //running average function prototype
int main()
{
int num;
do {
cout << "Enter numbers (enter -1 to exit): ";
cin >> num;
if (num != -1){
cout << "Running average is: " << r_avg(num);
cout << '\n';
} while (num != -1);
return 0;
}
//compute a running average.
int r_avg(int i)
{
staticint sum=0, count=0; //intialize sum and count
sum = sum + i;
count++;
return sum / count; //returns the running average
}