#include <iostream>
using namespace std;
int main()
{
int cnt = 0, // Count of numbers read.
tot = 0; // Total of numbers read.
int num; // Input number.
// Read until a read fails.
while(cin >> num) {
tot += num;
++cnt;
}
/* Print the average. */
if(cnt)
cout << "Average is " << (double)tot / (double)cnt << endl;
else
cout << "No numbers." << endl;
}
This one uses the result of an I/O operation as while test,
and an integer for an if test.