This isn't perfect and I'm not going to post code but here is a simple solution.
check if there is a remainder when you divide x by y
if there is then output variable x "/" variable y
if there isn't a remainder then output the result of x/y
I'm assuming that this is for a class. If it isn't then I'd be happy to post code. I'll try to think of a better solution in the meantime.