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.
so i guess what i need help with is, when the user enters the same name what do i do and also displaying the 5 names in the end. What loop would i use or while statement.
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/ http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
Looking over your program It will not work.
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.
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/ http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
Looks like it will work, but I will have to test it.
Your use of while loops will work, but a simple for loop is all yo really need fo this.
Andy
P.S. It is not nice to invade someone else's topic. Also the idea is to help someone learn not give them the answer.