How do I use CHECKLOCKTIMEVERIFY to prevent a transaction being spent before 100 blocks?
Yes, you can use OP_CHECKLOCKTIMEVERIFY to make a transaction output unspendable for a certain number of blocks.  However, you can't use it directly in an if-else block as you have described.  When OP_CHECKLOCKTIMEVERIFY executes, it doesn't place a result value on the stack.  It either throws an error (invalidating the transaction attempting to spend the output), or continues executing as if nothing happened.

To create a transaction as you describe, you will need to use multisig, such that one party can spend the transaction as soon as the correct number is provided (input to a hash function, I presume?), OR you can spend it back to yourself after the lock time expires.  This is basically how the lightning network works.  You should check out Lightning Networks Part II: Hashed Timelock Contracts (HTLCs)