-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathName_Search.cpp
44 lines (40 loc) · 1.28 KB
/
Name_Search.cpp
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
#include <iostream>
using namespace std;
int main(){
const int CAP = 50;
string names[CAP] = {
"John", "Mary", "James", "Patricia", "Robert", "Jennifer",
"Michael", "Linda", "William", "Elizabeth", "David", "Barbara",
"Richard", "Susan", "Joseph", "Jessica", "Charles", "Sarah",
"Thomas", "Karen", "Christopher", "Nancy", "Daniel", "Lisa",
"Matthew", "Margaret", "Anthony", "Sandra", "Donald", "Ashley",
"Paul", "Kimberly", "Mark", "Emily", "George", "Donna",
"Steven", "Michelle", "Kenneth", "Carol", "Andrew", "Amanda",
"Joshua", "Melissa", "Kevin", "Deborah", "Brian", "Stephanie",
"Edward", "Rebecca"
};
string query;
char sentinel;
int counter = 0;
bool found;
while(sentinel != 'q'){
cout << "Enter Name" << endl;
cin >> query;
found = false;
int i = 0;
for(int i = 0; i < CAP; i++){
if(query == names[i]){
cout << "The name " << query << " does exist at position " << i+1 << endl;
counter++;
found = true;
}
}
if(!found){
cout << "The name " << query << " does not exist" << endl;
}
cout << "Do you wish to quit? Enter q to quit" << endl;
cin >> sentinel;
}
cout << "You have left the loop and guessed " << counter << " name correct" << endl;
return 0;
}