That is nice, but Having some difficulty. Does not tell me what part of your code you are having trouble with.
Post what you have done and point which part(s) you are having trouble with.
If you do not know where to start then start with this: Ask the user for five names. Do what is needed to get this part to work first before you add If the user enters the same name twice, give a warning and continue asking.
You have defined "name" as a single string followed by entering five times into the same string. This will leave you with "name" containing the last entry made.
"name" needs to be an array or vector. Right now I am not sure what you have used if either.
Next the program could use a function to check for a duplicate name. Which would need to be called after you enter the second name and each name after that.
At the end of main you can use another for loop to print the names.
How familiar are you with arrays and loops? I think you should create an array of strings to hold the values entered by the use. I would use a loop to collect the user input, I would create another loop nested within the input loop that tests for duplicate entries by comparing the current element to all prior elements of the array. I would then create another loop to print the results to the console.
The nest loop should have a control structure that tests for a match between the value at the current index and the value of the previous elements in the array. If the values are found to be equivalent then the index value should be decremented so that the string can be re-entered and the nested loop should exit immediately.