compare new content to an array for duplicates

I have an assignment that requires me to write C++ code that asks user for an input a number of times, but notifies them IF the input is a duplicate of another input.

I have created the array but I am having a mind block on how to validate the latest input from the user against information that has already been entered to determine if a duplicate exist.

I am really new to C++, I have spent the last 2 days trying to work this problem out on my own but I am just not getting it!

Any assistance would be appreciated.
Thanks
AlamoGuy
You have some old values.
You have new value foo.
If foo equals any of the old values, then it is a duplicate.

In other words, you have to look at each of the old values -- one at a time -- and if any is equal to foo, then ...
OK, maybe a silly question, but like I said I am new to this programming thing, but what is "foo" what does it stand for?
I tried to use an IF statement such as:

>IF ((data[i] == data [0]) || (data[i] == data[1]) || (data[i] == data [2])) {
cout << "That entry already exist";

but it didn't work. The array isn't very large it is only set at [10], I thought about creating a FUNCTION to check for duplicates, but for the life of me I can't think it through. BTW I have been out of school for over 30 years, and only now learning about programming as a potential new career venture. I worked in public service before, so I am probably alot slower than most here.
Thanks
"foo" is just a made up name.

What you need is a loop. http://www.cplusplus.com/doc/tutorial/control/


Standard library has a function std::find http://www.cplusplus.com/reference/algorithm/find/

You were right about creating a function. That keeps things "simpler". std::find is such function.
Topic archived. No new replies allowed.