In the CS50 lab, to the left side of the sandbox, there's documentation, a text walk through and a video walk through. Read through, and watch the video to get a better understanding of the problem. It's easier to separate the problem into chunks (such as accepting the correct user input) and test to see that each chunk works, so that once it does the thing you want it to, you can almost forget about it. Using Printf to let you know what the values are at each stage helps. In the CS50 lab sandbox you can make a new file tab so that you can test stuff out on its own before putting it all together. Also, creating a .txt file and writing a pseudocode approach for how you're planning on solving each bit helps lots.
It's probably better if nobody tell you exactly how to solve the problem, because if you have to figure it out on your own, you will learn and remember it better because you really have to understand the problem. Good luck, you'll get it.