"Is not working properly" is not a good starting point to search for an error. Could you please be a little more specific.
What I can see right away is that the condition
qual=='pg'
can't work if qual is of type char.
qual
can only store a single character!