Program Error! Don't understand why

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
int number, sum1, sum2, counter, limit, integer;

ifstream inFile;
ofstream outFile;

inFile.open("Lab5data");

sum1 = 0;
sum2 = 0;
counter = 0;

while (inFile)
{
inFile >> number;
number / 2 = integer;
22 if (integer = 0);
sum1 = sum1 + integer;
counter++;

27 else
sum2 = sum2 + integer;
counter++;

}

cout << "The sum of the even integers read is " << sum1 << endl;
cout << "The sum of the odd integers read is " << sum2 << endl;


system("pause");

return 0;
}

I am getting an error saying Error error C2106: '=' : left operand must be l-value (line 22), and Error error C2181: illegal else without matching if (line 27)
I'm not really sure why the compiler is saying these things, please help!
Your syntax is all wrong.

Comparisons require the use of the '==' operator. The '=' operator is only for assignments, and the variable being assigned to must be on the left.

Also, you need to put brackets around your statements following if/else and don't put a ';' following an if statement.

Also, you want to use the modulus(%) operator and not divide because an int variable can't hold a fraction.
1
2
3
4
5
6
7
8
9
10
11
integer = number % 2;
if (integer == 0)
{
   sum1 = sum1 + integer;
   counter++;
}
else
{
   sum2 = sum2 + integer;
   counter++;
}


Also, indent following brackets like I did and for the future use the code tag for posting code.

Last edited on
Topic archived. No new replies allowed.