#include "stdstuff.h" int main () { int counters[10] = {0}, i; double rainfall; ifstream fin("data.txt"); for (;;) { fin >> rainfall; if (fin.fail()) { break; // must be end of file (file is assumed to be error free) } // compute counter array index and increment the element i = (int) (rainfall / 5); if (i > 9) { i = 9; } counters[i]++; // same as "counters[i] = counters[i] + 1" } // end for (;;) cout << endl << " Rainfall Occurrences" << endl << "---------------------------------" << endl; for (i = 0; i < 9; i++) { cout << setw(4) << (i * 5) << " to " << setw(2) << ((i * 5) + 4) << ".999 mm" << setw(10) << counters[i] << endl; } cout << " 45 and over mm " << setw(10) << counters[i] << endl; pause(); return 0; }