#include<fstream>
using namespace std;

main() {
       ifstream infile;
       ofstream outfile;
       int num, pcount=0;

       infile.open("numbers2.txt");
       outfile.open("evennumbers.txt");

       for(int count=0, count<20; count++) {
               infile>>num;
               if(num%2=0);
               pcount++
               }
               outfile<<"number of positive num is "<<endl;

               infile.close();
               outfile.close();
               system("pause");
               }

The == operator is used for comparison, it's different from the = operator which is used for assignment. Also, it may seem confusing at first, but you don't end the line of an if statement with a semicolon. It's legal, but doesn't do what you want.

Simple statements do end in a semicolon, and the prefix ++ is technically a little more correct than the postfix ++ because it's theoretically faster and more clear what you want in this case.

Compare and contrast:

if (num % 2 ==0)
    ++pcount;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.