I am learning C++ through the book C++ HOW TO PROGRAM by Deitel & Dietel. I tried an array program that is supposed to count the frequency of one array by using a second, but the program doesnt work when I try to compile it. It returns a value of 0 for all subvalues of array Frequency[]. I am using Visual C++ 6.0 on a PC. heres the program:
////////////////////////////////////////////////////////////////
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <iomanip>
using std::setw;
int main()
{
int responses[40]={1,2,6,4,8,5,9,7,8,10,1,6,
3,8,6,10,3,8,2,7,6,5,7,6,8,6,7,5,6,6,5,6
,7,5,6,4,8,6,8,10};
int frequency[11]={0};
for (int answer=0;answer<40;answer++);
***--------->*** ++frequency[ responses[ answer ] ];
cout<<"Rating"<<setw(17)<<"Frequency"<<endl;
cout<<frequency[5]<<endl;
for (int rating=1;rating<11;rating++)
cout<<setw(6)<<rating
<<setw(17)<<frequency[rating]<<endl;
return 0;
}
////////////////////////////////////////////////////////////////////////////////////
The debug shows the problem to be with the starred line, and im assuming it is because of the ++ but i dont know how to add 1 to that array value using a different method. Please help!