if statment problems

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;
     }
You if statement is incorrect...I think you meant iFood > 0?
ya i tried that to but it doesnt work for some reason
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.
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
Topic archived. No new replies allowed.