Mar 8, 2015 at 10:36am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13
int x = 0;
while ( x <= 0 )
{
cout << x << endl;
if ( x == -1 )
cout << "Negative" << endl;
x--;
}
Logic error?
Last edited on Mar 8, 2015 at 11:16am UTC
Mar 8, 2015 at 10:51am UTC
What are you trying to accomplish?
Mar 8, 2015 at 10:54am UTC
What do you mean won't run? Does it not compile, or does it not do what you want it to do?
Mar 8, 2015 at 11:14am UTC
I'm told there's a "logic" error.
Last edited on Mar 8, 2015 at 11:15am UTC
Mar 8, 2015 at 12:04pm UTC
Well, this loop will certainly go forever. Presumably, this wasn't the goal, which is why I was asking what you are trying to accomplish. It's hard to tell what the logic error is without knowing the goal.
Mar 8, 2015 at 12:37pm UTC
I was given that code and told that there is a "logic" error. That's it, that's all the info I have.
Last edited on Mar 8, 2015 at 12:37pm UTC
Mar 8, 2015 at 12:38pm UTC
Perhaps the answer is just that: that it is illogical to have a loop go on forever?
Last edited on Mar 8, 2015 at 12:38pm UTC