Quote (ben_graham7 @ Apr 2 2013 01:58pm)
I'm trying to get my program to determine if a number is even or not. If it is even, I want the counter to be 1 number higher. If it is odd, I want the counter to be that number.
There's an error, but I'm not sure what I did wrong.
Here's the section of code:
if (firstNum % 2 = 0)
counter = firstNum + 1;
else
counter = firstNum;
Here's the error message:
ProgD.java:25: error: unexpected type
if(firstNum % 2 = 0)
^
required: variable
found: value
you are assigning a value rather than checking for equality.
= is for assignment
== is for checking equality
also im not sure what you mean by counter but if you mean you want to keep track of evens vs odds it is much simpler just to create two variables (int evens, odds; respectively) and just increment as evens++; and odds++; when the conditions are true.
This post was edited by AbDuCt on Apr 2 2013 12:11pm