What percentage of the code should be yours in a final year computer science project?
If I change that code with my variable names and create functions and add that code into those functions would that be a problem ?

That seems like blatant plagiarism: Taking code and changing variable names surely only serves plagiarism. Creating new functions from existing code surely only serves plagiarism too.

what do I do ?

Use as much external code as you like. That code should appear as-is, with any ownership, copyright, and licensing information intacted, where ownership information is missing, perhaps add it, at the very least, document the fact that code isn't yours.
Write your own code that uses external code. That's your contribution.
Occasionally, you may use an external code snippet within your code. Mark such code with comments, e.g., /** BEGIN: Code from xyz **/ and /** END **/.
Ultimately, your goal should be to achieve your objective with minimal code.