Benford's Law

Hi! so I have to write a C++ program to analyze three different data
files, and try to confirm Benford’s law. I need to create a console application that opens each file, counts the number of values that start with ‘1’, ‘2’, ‘3’, etc., and then outputs the percentages of each digit.

I think I wrote it correctly but I keep getting error from Dev C++
here's where it is in my program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int analyzeData(string fname)
{
    ifstream infile(string fname);
    int tmp,count = 0;
    float percents[9];
    int nums[9] = { 0 };
    if(!infile.good())
        return 1;
    while(!infile.eof())
    {
        infile >> tmp;
        tmp = first(tmp);
        if(tmp > 0)
        {
            nums[tmp - 1] ++;
            count++;
        }
    }


It says that 'good' 'infile' and 'eof' are non-class type?
I don't know what that means. Help would be much appreciated! Thanks!
line 3: remove string from arguments.

Also do not use while(!infile.eof()) it is root of many mistakes. In your case use
1
2
3
while(infile >> tmp) {
    tmp = first(tmp); 
//... 
Last edited on
Topic archived. No new replies allowed.