Results 1 to 9 of 9

Thread: illegal operations

Threaded View

  1. #1

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037

    illegal operations

    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;
    }
    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.
    Last edited by aewarnick; Jan 7th, 2003 at 11:31 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width