make some sort of check, which would say:
Code:
if number N=P != N+1=P+1 then Error
The only way I could see this sort of code running without alot of if/then/else clauses would be to make an array or better yet a dynamic array or even better, making it C++, with the use <vector> and any sort of mapping() function onto that.