Problem with my search function

so my program is your common student information system.. so i was making my own then when i try my search function nothing gets displayed idk.. what happening am i missing a code or something?
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
  #include<iostream>
#include<string>
#include<conio.h>
#define size 100
	using namespace std;

	int main()
	
	{
		
		char myinput;
		string nam[size],add[size],con[size],cor[size],yel[size];
		string search;
		int num_rec,a;
		string idn[size];
		
		a=0;
		
		do
{
system("cls");

	 cout << "\t\t====== STUDENT INFORMATION SYSTEM ======";
     cout <<"\n\n                                          ";
     cout << "\n\n";
     cout<<" \n\t\t\t======================";
     cout << "\n \t\t\t  [1] Add    Records";
     cout << "\n \t\t\t  [2] Search Records";
     cout << "\n \t\t\t  [3] Modify Records";
     cout << "\n \t\t\t  [4] Delete Records";
     cout << "\n \t\t\t  [5] Exit   Program";
     cout<<" \n\t\t\t======================";
     cout << "\n\n";
     cout << "\t\t\t Select Your Choice :: ";
	 cin >> myinput;


		switch (myinput)
				{
					{
		case '1':
			{
			system("cls");
			
		cout<<"** Number of records to be entered (MAXIMUM OF 10) **"<<endl;
			cout<<"# ";
			cin>>num_rec;
			
if (num_rec < 11)
{
	for (a=0; a<num_rec; a++)
	{
	cout<<"Enter your ID number:: ";
	getline (cin, idn[a]);
	cout<<"Enter your Name:: ";
	getline (cin, nam[a]);
	cout<<"Enter your Address:: ";
	getline (cin, add[a]);
	cout<<"Enter your Contact Information:: ";
	getline (cin, con[a]);
	cout<<"Enter your Course:: ";
	getline (cin, cor[a]);
	cout<<"Year Level:: ";
	getline (cin, yel[a]);
	
	cout<<"\n\n\n You have Successfully entered the record(s)"<<endl;
	
	}
}
else
{
cout<<" The system cannot handle more than "<<num_rec<<" records"<<endl;
					
}
cout<<"\n\n\n\n\n************************************************"<<endl;
cout<<"***Please press any key to return to the Menu***"<<endl;
cout<<"************************************************"<<endl;

       getch();

					break;
		
		
		}
					}
		case '2':
			{
			  system("cls");
 cout<<"** Search and display student's details **"<<endl;
 cout<<"Type student's ID NUMBER : ";
 cin>>search;
 cin.ignore();
                 
for (a=0; a < num_rec; a++)
{
 if (search==idn[a])
{
 cout<<"NAME ::"<<nam[a]<<endl;
 cout<<"ADDRESS ::"<<add[a]<<endl;
 cout<<"CONTACT INFORMATION ::"<<con[a]<<endl;
 cout<<"COURSE ::"<<cor[a]<<endl;
 cout<<"YEAR LEVEL ::"<<yel[a]<<endl;
						
 }
 else
 {
cout<<"NO RECORDS FOUND"<<endl;
					  }

cout<<"\n\n\n\n\n************************************************"<<endl;
cout<<"***Please press any key to return to the Menu***"<<endl;
cout<<"************************************************"<<endl;

  getch();
break;
                  }
          }
   }
}

while(myinput!=5);
		return 0;
	}
Last edited on
Please learn to use a consistent, sensible indentation style. It will make it much easier for both you and us to see the flow of control through your code at a glance, and it will help you spot errors much more easily.
sorry i was kinda in a rush..
Don't apologize to us - sensible code indentation is something that helps you. Spending a few seconds making sure your layout is sensible can save you considerably more time hunting errors.
Last edited on
oh thanks then... i was already fixing the indentations of my code but still I cant find whats making my search function well...Function.
Get an IDE which can highlight paired braces and look where closing brace for your for loop in case 2 is.
i got the search function to work but this time only the first one student info i add is the only one that can be search when i search for other student info they wont show..
The proble is that you are writing "NO RECORDS FOUND" after processing each student which is not that you search for and "Please press any key to return to the Menu" after eack operation.

You sshould output "Not found" message only if there really no records you search for and "return" message only once at the end
Add an extra "getline(cin,ext[a]);" before "getline (cin, idn[a]);". And also bring the "NO RECORDS FOUND" out of for() loop.
Topic archived. No new replies allowed.