Loop with > test terminating when they're same
Aug 6, 2011 at 8:19am UTC
Basically as title states.
1 2 3 4 5 6 7 8 9 10 11 12
double daph = 100;
double cleo = 100;
int year;
for (year = 0; cleo < daph; year++)
{
cleo = cleo * 1.10;
daph = daph + 10;
}
cout << "After " << year << " years, cleo has " << cleo << " dollars in her account, " ;
cout << "and Daphne has " << daph << " dollars in her account." ;
It terminates at 0 runs and outputs them as their starting values.
It's not a homework problem, I'm working through C++ primer by Prata
Aug 6, 2011 at 8:31am UTC
The condition you put in a for is a condition you need to meet to continue looping. You seem to be thinking about it as an 'until'.
100 < 100 is false, so the loop is never executed.
Topic archived. No new replies allowed.