I have the following problem: pre-condition is True
int n = askUser();
int i = 0;
while(i<n){
...
i++;
}
The variant I am thinking of is: n-i
.
However, I don't think there is anything that stops the user from supplying a negative value, and in that case the variant will be negative (which contradicts its definition).
Is it possible to specify the invariant as |n| - i, or does n>=0 has to be included as pre-condition?
Any help or suggestions will be greatly appreciated.