//* Controlling repetition with a while loop - 3 (for loop) - known number of items *

#include <iostream> using namespace std; int main() { int total_cnt; cout << "Please enter the number of data items to be entered: "; cin >> total_cnt; double sum=0.0; for (int cnt=0; cnt<total_cnt; cnt++) { cout << "Please enter the "<<cnt<<"th data item: "; // my apology to 1st, 2nd, and 3rd !!! // we try to keep this program simple double x; cin >> x; sum+=x; } double avg; if (cnt>0) avg= sum/cnt; else avg=0.0; cout << "The average of entered numbers is " << avg << endl; return(0); }