how to count a specific number from a file in c++
<p>Yes, this is a question for a class, but I don't want my homework done for me.  I just need to figure out where I'm going wrong.  The question that I have to figure out states this: </p>

<p><strong><em>Write a program which uses the file produced in Lab 1 as its input file.  This program gets user input of a value from 1000 to 10000, and counts how many times the user's value appears in the input file.  It reports to the user using screen output.</em></strong></p>

<p>Here's the code that I have after several failed attempts:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;


using namespace std;

int count(int number, int input, int length)
{
    int counter = 0;
    for(int i = 0; i &lt; length; i++)
        if(input == number)
            counter++;
    return counter;
}

int main()
{
    int num,input;

    ifstream fin;
    fin.open("ran_num.txt");
    if(fin.fail())
    {
        cout&lt;&lt;"Input file opening failed."&lt;&lt;endl;
        cin.get();
    }

    cout&lt;&lt;"Enter a number between 1000 to 10000:";
    cin&gt;&gt;num;

    fin&gt;&gt;input;

    cout&lt;&lt;num&lt;&lt;"appears "&lt;&lt;count(num, input, 3000)&lt;&lt;" times in the file."&lt;&lt;endl;

    return 0;
}
</code></pre>

<p>I'm completely lost and just need to figure out what I use to count a user inputer value.  Any help is appreciated!</p>

<p><strong>Edit</strong>
This is what I have now.  My program can now read the whole file, but I still do not know how to count a user-inputted number.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;iomanip&gt;


using namespace std;

int main()
{
    ifstream fin("ran_num.txt");
    int num, user_input;

    cout&lt;&lt;"Enter a number between 1000 to 10000:";
    cin&gt;&gt;user_input;

    while(fin&gt;&gt;num)
    {
        if(num == user_input)
        {
            cout&lt;&lt;count++;
        }
    }
    return 0;
}
</code></pre>