/* Filename: readkeyb.cpp Author: Br. David Carlson Date: January 8, 2000 Modified: June 26, 2000 This program reads floating point numbers from the keyboard and finds and prints their average. The numbers should be entered one at a time, as prompted. Use CTRL z to end data input. */ #include using namespace std; int main(void) { float Num, Total; int Count; Count = 0; Total = 0.0; cout << "Enter a floating point number (or CTRL z to end): " << endl; cin >> Num; while (! cin.fail()) { Total = Total + Num; Count++; cout << "Enter a floating point number (or CTRL z to end): " << endl; cin >> Num; } if (Count > 0) cout << "Average is " << Total / Count << endl; else cout << "No data given" << endl; return 0; }