I have another question for my homework. Here is the problem:
Keep inputting numbers from the user until the user enters a 0. After each number, print a "running average". That is, print the average of the last three numbers entered. Be careful how you handle the first two numbers entered, before there are three numbers for the running average. (I'll accept any reasonable solution to handling the first two numbers).
So far, I have:
#include "stub.h"
int main()
{
int x;
int sum = 0;
int num1;
int num2;
int num3;
do
{
cin >> x;
sum = sum + x;
counter = counter + 1;
num1 = x;
num2 = num1 + x;
num3 = num1 + num2 + x;
cout << num3/3 << endl;
}
while (x!=0);
if(x==0)
return 0;
cin.get();
getchar();
return 0;
}
This isn't working for me, and I'm not sure how to fix it or how to get the average of only the last three inputted numbers.