Every time I run this it loops up to 185 and then says it performed an illegal operation. Even if I put -1 as the first score.Code:#include <stdio.h> #include <iostream> #include <cstdlib> #include <iomanip> using namespace std; int main(int argc, char *argv[]) { int R, F=R+1; cout << "How many people are there? "; cin >> R; int responses [20]= {0}; // initialize all memory locations to 0. int frequency [21]= {0}; cout << "Enter scores: " << endl; for (int i=0; i<=R; i++){ cin >> responses[i]; if (responses[i]<=-1) break; } for (int answer=0; answer <=R; answer++) ++frequency [responses[answer]]; // This is the key to it all!!! cout << "Number" << setw(14) << "Frequency" << endl; for (int rating=1; rating <=F; rating++) cout<< rating << setw(11) << frequency[rating] << endl; system("PAUSE"); return 0; }




Reply With Quote