First design the program, then code the program from the design. First, in detail, how would you do this using pen/paper? What instructions would you give to someone else who knew nothing about triangles? When you can document these, then produce the design and then the code.