Originally posted by jake kodak:
how is this
What are you asking?
Does it compile? Why don't you find out!
Has it got any chance of achieving what you are trying to do? You haven't said what you are trying to do! If you are trying to write a program,
you should start by stating what the program is meant to do. Then someone can help you work towards that goal.
But I doubt that is the case. This looks like the sort of mental puzzle that instructors set to teach students to read and understand code. The point of such an exercise is to predict the outcome from reading the code, before running it to confirm your answer. But the instructions seem to have become garbed.
My guess is that the problem you have been set is to work out what your code would print out, if it ran. It has two variables, which it initializes and then repeatedly increments and decrements as indicated until they cross over. Look at the logic and work out what the output should be. If you need to, manually execute each line of the loop over and over, recording the value of each variable at every line, until the loop exits. If you can't do it in your head, write it down.
Once you think that you know the answer (assuming that I have correctly guessed the problem that you have been set), you should take the code you originally posted, and:
Delete the unnecessary first declaration of up;Change the while loop to the for loop that it is obviously meant to be;Add the required semi-colon after the second up++ Your program should then compile. Run it and see if the output is what you expect.
I hope this helps. If my guess about your problem is not correct, perhaps you could respond with the correct details.