Array Search Function

So I am supposed to loop through my array and be able to find a certain "name" that the user inputs. I think I am having problems with looping my array, and i am not sure how to use that array to fin d a certain name. Any help would be greatly appreciated. Thanks!

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// Rolodex.h
//  Rolodex.h

#include "Card.h"

const int NUM_CARDS = 30;

#ifndef ROLODEX_LOCK
#define ROLODEX_LOCK

class Rolodex
{
public:
    Rolodex();
    Card obtainCard();
    void addCard( Card userCard );
    void resetList();
    void deleteCard();
    void changeCard();
    void findCard( string name );
private:
    int currentCardIndex;
    Card cards[ NUM_CARDS ];
};

#endif


// Rolodex.cpp
//  Rolodex.cpp

#include<iostream>
#include "Rolodex.h"

using namespace std;

Rolodex::Rolodex()
{
    currentCardIndex = 0;
}

Card Rolodex::obtainCard()
{
    return cards[currentCardIndex];
}

void Rolodex::addCard(Card userCard)
{
    if (currentCardIndex == (NUM_CARDS - 1))
    {
        currentCardIndex = 0;
    }
    else
    {
        ++currentCardIndex;
    }
    
    cards[currentCardIndex] = userCard;
}

void Rolodex::resetList()
{
    currentCardIndex = 0;
}

void Rolodex::deleteCard()
{
    if (currentCardIndex == 0)
    {
        currentCardIndex = (NUM_CARDS - 1);
    }
    else
    {
        currentCardIndex--;
    }
}

void Rolodex::changeCard()
{
    obtainCard();
    if (currentCardIndex == (NUM_CARDS - 1))
    {
        currentCardIndex = 0;
    }
    else
    {
        ++currentCardIndex;
    }
}

void Rolodex::findCard( string name )
{
    Card myCard;
    for ( int i = 0; i < NUM_CARDS; i++)
    {
        if ( myCard.getName() == name )
        {
            currentCardIndex = i;
            
        }
    }
}


//  workerBee.cpp


#include "workerBee.h"
#include "Card.h"
#include "Tools.h"
#include "Rolodex.h"
#include<iostream>
#include<string>
#include<array>
using namespace std;

void workerBees(void)
{
    workerBee();
}

void workerBee(void)
{
    char userChoice;
    do
    {
        Rolodex rolodex;
        Card myCard;
        
        
    
        userChoice = getChar("Select operation: a)dd, d)elete, r)eset, n)ext, f)ind, q)uit: ");
     
        switch ( userChoice )
        {
            case 'a':
            case 'A':
            {
                string inputNames;
                string inputNumber;
                
                inputNames = getString("Enter name for Rolodex card (0 to quit): "); // Names to be entered by user
                inputNumber = getString("Enter phone number for Rolodex card (0 to quit): "); // Numbers to be entered by user
               
                myCard.setName(inputNames);
                myCard.setNumber(inputNumber);
                rolodex.addCard(myCard);
                
                cout << "Current card is " << myCard.getName() << " ------------ " << myCard.getNumber() << "." << endl;

            }
                break;
            
            case 'd':
            case 'D':
            {
                rolodex.deleteCard();
            }
                break;
            
            case 'r':
            case 'R':
            {
                rolodex.resetList();
            }
                break;
            
            case 'n':
            case 'N':
            {
                rolodex.changeCard();
            }
                break;
            
            case 'f':
            case 'F':
            {
                string inputNames = getString("Which name would you like to find? ");
                rolodex.findCard(inputNames);
            }
                break;

            case 'q':
            case 'Q':
            {
                break; // done
            }
        }
    } while ( ! (( userChoice == 'q' ) || (userChoice == 'Q')) );
}
How do you know it doesn't work if you don't even tell the user what happened? Something needs to go between lines 179 and 180.

Also, line 93 shouldn't exist.
Last edited on
Topic archived. No new replies allowed.