Hello everyone. Could someone explain me, what's wrong with this code? It doesn't do the condition, which I wrote in the while. Even if i write negative number, it still makes the while loop.
Thanks for the help, guys.
The while loop is going through because the condition x != y*y is always being met. So, even if the user enters a negative number the loop will go through.
EDIT: Sorry, the condition is not ALWAYS being met, but until x=y^2 is entered the user is free to enter negative numbers.
Because of this condition x != (y*y) and the line y = x; on the previous line, the only way the while loop won't execute is if x == 0 or x == 1.
EDIT: Given that x would have to be 0 or 1, going back to the first condition of the while you can rule out x == 1. So the only value for x that would not enter the while loop would be 0. Beyond that, the condition of the initial 'if' rules out x being zero. There's no way a user can input anything to avoid the while loop.
I'm very sorry about this.
To be certain:
1)The person should enter the sequence of numbers till the minimal number would be two times lower that the maximal number.
So, first of all, the person enter the number. First 'if' statement in the loop checks whether the entered number is two times bigger than the previous maximal number. If it's not - make the new number -maximal.
Else statement checks whether the new entered number is two times lower the maximal number and if not asks to write the x again.