Work on it step by step, making sure each bit works before moving on to the next bit. Don't try to write the whole program in one go before compiling it.