Well you don't have anywhere in the code that would put a " " in hyphened phrase. You could just add an if statement to the first for loop that checks if the current index is a " ", and if it's not then go to the second loop.
Also you don't account for uppercase letters in your 2nd loop. You could just use toupper or tolower and that would fix it.