Help troubleshooting

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.

Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* This computer computes a running average of numbers
entered by the user */

#include <iostream>
using namespace 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) 
          {
          static int sum=0, count=0; //intialize sum and count 
          sum = sum + i;
          count++;
       
       return sum / count; //returns the running average
       }
 


Any help would be great.

Thank you!
By my count, you're one } short, somewhere in your main function (between lines 16 and 18?).

Happy coding!

-Albatross
ughhh! My bad.

Thank you!
Topic archived. No new replies allowed.