It's a question a believer and a nonbeliever can spend time considering and arrive to very different conclusions. A nonbeliever may see the existence of pain and suffering in this world as proof that a good God doesn't exist. I'd like to ask you, no matter which of those two you identify most with, to consider: if a good God created a world in which pain and suffering could be possible, wouldn't He have good reasons to create it and do something about it?
Although we may not fully comprehend why God would create a world with the potential of pain and suffering, something that we are able to acknowledge is that it is the worse situations in our life that teach us the most and form our character for the better. We are humbled by the reality of our weaknesses in difficult situations and we are forced to look for the strength and grace only someone greater can grant us. In our pain, we are not looking for philosophical answers as much as we are searching for the God that knows more than us. We search for the hope that is only found in His words.
Explanations going in depth into man's free will and God's sovereignty are plentiful, but practically speaking, in the midst of pain and suffering we need a person to comfort us and help us to function again. That person is the God who designed us and knows what we need and the moment we need it. When we are lost, we are found by Him. When we don't have it in us to do the right thing, He helps us do it. When we don't understand, He shows us reasons to trust Him and His love. Continue searching for philosophical answers, but seek even more the Person who entered our world full of pain and suffering by dying a gruesome and shameful death on the cross, promising to one day wipe away every tear from the eye of those that believe in Him.
Further Reading Book Suggestion: "The Case For Faith" by Lee Strobel