-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaticArray.cpp
More file actions
42 lines (35 loc) · 880 Bytes
/
StaticArray.cpp
File metadata and controls
42 lines (35 loc) · 880 Bytes
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
#include <iostream>
#include <string>
using namespace std;
void search(string names[], int size, string name) {
for(int i = 0; i < size; i++) {
if(names[i] == name) {
cout << "Found " << name << " at index " << i << endl;
return;
}
}
cout << name << " not found in the array." << endl;
}
int main() {
int size;
cout<<"enter the size : ";
cin>>size;
string names[size];
for(int i = 0;i<size;i++){
cin>>names[i];
}
cout<<"names : "<<"[ ";
for(int i = 0;i<size;i++){
cout<<names[i]<<" ";
}
cout<<"]"<<endl;
string resp;
cout<<"Searching for a name ? ";
cin>>resp;
if(resp =="yes" || resp == "Yes" || resp == "YES"){
string name;
cout<<"enter the name : ";
cin>>name;
search(names,size,name);
}
}