checking for duplicates array

Hi. I'm trying to check for duplicates and prevent them from being added in my array. I wrote a loop in the addin function to check if a name is a duplicate and display a message asking you re-enter. When i run the code though each time a name is entered the message is displayed whether its a duplicate or not. Any suggestion would be appreciated

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
[code] #include "stdafx.h"
  #include <iostream>
  #include <stdio.h>
  using namespace std;

  const int datamax = 10;
  void addin(char table[5][2][40]);

 int main()
 {
 char tb[5][2][40];
 char response;
 int i = 0;
 cout << "What to do" << endl
      << "A to Add" << endl
    << "Q to Quit" << endl;
cin >> response;
cin.clear();
cin.ignore();

for (i = 0; i < 10 && (response != 'q' || response != 'Q'); i++)
{
    if (response == 'a' || response == 'A')
    {
        addin(tb);
    }
    else
    {
        return 0;
    }
    cout 
        << "What to do" << endl
        << "A to Add" << endl
        << "Q to Quit" << endl;
    cin >> response;
    cin.clear();
    cin.ignore();
}
return 0;
 }
void addin(char addin[5][2][40])
{
static int i = 0;
bool answer = true;
int j = i + 1;
cout << "Please enter name" << endl;
gets_s(addin[i][0]);
if (addin[i][0] == addin[j][0]) {
    answer = true;
}
if (answer == true)
{
    cout << "Please re-enter name " << i + 1 << ". Duplicate names are not allowed:" << endl;
    cin >> addin[i][0];
    cout << "please enter number" << endl;
    cin >> addin[1][1];     
}
answer = false;
i++;
}

Last edited on
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/general/198263/

Please don't double post. I realise there is a bit of confusion going on in the other post but pick one thread and green tick the other. If you're not getting anywhere just add a comment in the thread you choose to keep open and it will bump the post to the top. :)
Topic archived. No new replies allowed.