0
#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");
               }
2
Contributors
1
Reply
4
Views
4 Years
Discussion Span
Last Post by deceptikon
0

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;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.