Using Update Operators
Code Examples
Reading In the While Test
multav3.cc
Watch Out For This
#include <iostream>
using namespace std;
main()
{
int cnt = 0, // Count of numbers read.
tot = 0; // Total of numbers read.
// Read until a read fails.
int num;
while(cin >> num) {
tot += num;
++cnt;
}
/* Print the average. */
if(cnt)
cout << "Average is " << (double)tot / (double)cnt << endl;
else
cout << "No numbers." << endl;
}
Reading: Ch.6
Reading In the While Test
Watch Out For This