@ dxwood ,thanks for your reply again, ON SIR JOHN's suggestion on the second part here i have a doubt that if i add make false the ended then it will never run the if condition so should it not be TRUE? :
if (ended)
{
ended = false; ///////// Add this
EDIT.. OK OK i got it was going haywire, sorry for that