if statment problems

Jan 5, 2011 at 3:00am
here im trying to double the population if there is food and half the food if there isnt any food, But for some reason its always halved
1
2
3
4
5
6
7
8
if (iFood < 0, 0)
     {
               iPopulation = iPopulation * 2;
     }
     else
     {
         iPopulation = iPopulation/2;
     }
Jan 5, 2011 at 3:03am
You if statement is incorrect...I think you meant iFood > 0?
Jan 5, 2011 at 3:06am
ya i tried that to but it doesnt work for some reason
Jan 5, 2011 at 3:08am
Remove the part after the comma, what is that doing there, anyway? With it, you are basically writing if(0), which will never be executed.
Jan 5, 2011 at 9:05am
closed account (SEbf92yv)
I assume when you wrote the post, you meant double the population if there is food, otherwise half the population.
Therefore you want to change the bracket slightly, by just simply changing the < to an >.

1
2
3
4
5
6
7
8
if(iFood > 0)  //if food is greater than 0
     {
        iPopulation = iPopulation * 2;  //then double population
     }
else   //otherwise
     {
         iPopulation = iPopulation/2;   //half the population
     }
Last edited on Jan 5, 2011 at 9:12am
Topic archived. No new replies allowed.