What's wrong with this?

Mar 8, 2015 at 10:36am
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
Mar 8, 2015 at 10:51am
What are you trying to accomplish?
Mar 8, 2015 at 10:54am
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
I'm told there's a "logic" error.
Last edited on Mar 8, 2015 at 11:15am
Mar 8, 2015 at 12:04pm
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
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
Mar 8, 2015 at 12:38pm
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
Topic archived. No new replies allowed.