Im trying to create a cyclinder with the bottom and top rounded but when i use the Sub divison modifier it leaves these creases at both ends and if i use a loop cut to smooth it out it makes the object to flat at both ends and not rounded how can i fix this?
Those ugly creases are caused by the n-gon cap. The Subsurf modifier works best with quads and doesn't work well at all with n-gons.
Here are two alternate methods of filling the cap which produce quads, and thus much better subdivision modeling.
The first example was made by selecting the n-gon face and then hitting E (exturde) and then S to scale the extrusion inward. You could move the extruded part up to make the top less flat.
The second example was made by joining half the opposing vertices, making a quad fan. This could also be done by using the Grid Fill option. Again, the central vertex could be lifted up to make the top more round.