I think the while loop qualifies as sentinel since you are looping until a certain sentinal value is attained, as opposed to looping a fixed # of times.
I see some problems with your while loop:
1) Only line 43 will be executed in the while loop. I think you want both lines 43 and 44 to do so.
Enclose all lines for the loop in curly braces. ie:
1 2 3 4 5
|
while (finalA > finalB)
{
finalA = ((growthRATEa / 100) * (popA)) + popA;
finalB = ((growthRATEb / 100) * (popB)) + popB;
}
|
2) Lines 43 and 44 won't change the values of popA and popB. finalA and finalB will never change values in the loop!
3) finalA and finalB are not initialized before the while loop so the first evaluation of finalA > finalB will give an unpredictable result.
4) I think you want while( finalA < finalB ) since the town A population is the one which is initially smaller. Were you thinking it meant
until(finalA > finalB)?
5) Skip the use of finalA, finalB, growA and growB altogether! These last 2 are never even used.
Try this instead:
1 2 3 4 5 6 7
|
while (popA < popB)
{
popA = ((growthRATEa / 100) * (popA)) + popA;
popB = ((growthRATEb / 100) * (popB)) + popB;
// you might want to increment a variable counting the years here
// since you are asked to output how long it takes for popA to equal popB
}
|
This corrects all of the flaws concerning the while loop.