im having problem with my code..please help me to figure out my mistake

Write your question here.

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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
  #include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
#include <windows.h>
using namespace std;


class patient
{

public:

    string fname;//first name
    string lname;//last name
    string ic;//ic no
    string age;//age
    string add;//address
    string no;//phone num
    string blood;//blood group

};

class doctor
{

public:

    string dfname;//first name
    string dlname;//last name
    string dqualification;
    string dexp;
    int dic;//ic no
    string dage;//age
    string dadd;//address
    string dno;//phone num
    string dblood;//blood group


};








int main()
{
    int i=0;
    int j;
    char sl;
    string find;
    string srch;
    patient p;
    doctor d;


    cout<<"************************************************"<<endl;
    cout<<"************************************************"<<endl;
    cout<<"******WELCOME TO PATIENT MANAGEMENT SYSTEM*****"<<endl;
    cout<<"************************************************"<<endl;
    cout<<"************************************************"<<endl;
    cout<<"******************By Praveen********************"<<endl;
    cout<<"\n\nPlease select 1 for patient";
    cout<<"\nPlease select 2 for doctor";
    cout<<"\nOption :";
    cin>>sl;
    system("cls");


	switch(sl)
	{
	    case '1':
{
while(1)//inner loop-1
    {
    system("cls");//Clear screen

	cout<<"\t\t\tPatient Data\n\n\n";
    cout<<"Enter your choice: "<<endl;
    cout<<"1.Create new entry\n";
    cout<<"2.Find record\n";
    cout<<"3.Jump to main\n";
    cin>>sl;

    switch (sl)//Second switch
	{
    case '1'://Insert data
    {  ofstream f1("patient.txt",ios::app);

    for( i=0;sl!='n';i++)
        {

    if((sl=='y')||(sl=='Y')||(sl=='1'))
    {
    cout<<"\n ENTER PATIENT FIRST NAME :";
	cin>>p.fname;
	cout<<"\n ENTER PATIENT LAST NAME :";
	cin>>p.lname;
	cout<<"\n ENTER PATIENT IC NO :";
	cin>>p.ic;
    cout<<"\n ENTER PATIENT AGE :";
	cin>>p.age;
	cout<<"\n ENTER PATIENT ADDRESS :";
	cin>>p.add;
	cout<<"\n ENTER PATIENT CONTACT NO :";
	cin>>p.no;
    cout<<"\n ENTER PATIENT BLOOD GROUP :";
	cin>>p.blood;

	 f1<<p.fname<<endl<<p.lname<<endl<<p.ic<<endl<<p.age<<endl<<p.add<<endl<<p.no<<endl<<p.blood<<endl;
    cout<<"Do you want to enter data: ";
    cout<<"Press Y for Continue and N to Finish:  ";
    cin>>sl;

    }
}
f1.close();
}
continue;//control back to inner loop -1



case '2'://Display data
{  ifstream f2("patient.txt");

cout<<"Enter First IC no to be displayed: ";
cin>>find;
cout<<endl;
int notFound = 0;
for(j=0;(j<i)||(!f2.eof());j++)
{
	getline(f2,p.ic);


  if(p.fname==find)
{
 notFound = 1;
 cout<<"First Name: "<<p.fname<<endl;
 cout<<"Last Name: "<<p.lname<<endl;

 getline(f2,p.ic);
 cout<<"IC NO: "<<p.ic<<endl;
 getline(f2,p.age);
 cout<<"Age: "<<p.age<<endl<<endl;
 getline(f2,p.add);
 cout<<"Age: "<<p.add<<endl<<endl;
 getline(f2,p.no);
 cout<<"Phone Number: "<<p.no<<endl<<endl;
 getline(f2,p.blood);
 cout<<"Blood Group: "<<p.blood<<endl<<endl;
}
}
if(notFound == 0){

cout<<"No Record Found"<<endl;
}
f2.close();
cout<<"Press any key two times to proceed";
getch();//To hold data on screen
getch();//To hold data on screen

}
continue;//control back to inner loop -1

case '3'://Jump to main
{
break;//inner switch breaking
}
}

break;//inner loop-1 breaking
}
//Control pass to 1st loop
}

//Doctor Case
case '2'://Doctor
{
while(1)//inner loop-2
{
system("cls");//Clear screen
//Level-2 Display process
cout<<"\t\t\tDoctor Record\n\n\n";
cout<<"Enter your choice: "<<endl;
cout<<"1.Create new entry\n";
cout<<"2.Find and display\n";
cout<<"3.Jump to main\n";
cin>>sl;

switch (sl)//Third switch
{
case '1'://Insert data
{
    ofstream t1("doctor.txt",ios::app);

for(i=0;sl!='n'&& sl!='N';i++)
{

 if((sl=='y')||(sl=='Y')||(sl=='1'))
 {
  cout<<"Enter First name: ";
  cin>>d.dfname;
  cout<<"Enter Last name:: ";
  cin>>d.dfname;
  cout<<"Enter qualification: ";
  cin>>d.dqualification;
  cout<<"Enter experiance(year): ";
  cin>>d.dexp;
  cout<<"Enter IC number :";
  cin>>d.dic;
  cout<<"Enter Age :";
  cin>>d.dage;
  cout<<"Enter Address :";
  cin>>d.dadd;
  cout<<"Enter Phone Number: ";
  cin>>d.dno;
  cout<<"Enter Blood Group: ";
  cin>>d.dblood;

  t1<<d.dfname<<endl<<d.dlname<<endl<<d.dqualification<<endl<<d.dexp<<endl<<d.dic<<endl<<d.dage<<endl<<d.dadd<<endl<<d.dno<<endl<<d.dblood<<endl;
  cout<<"Do you want to enter data: ";
  cin>>sl;
 }//if
}//for loop
//for finding through name
system("cls");

	  t1.close();
}//case 1

continue;//Control pass to inner loop-2

case '2'://Display data
{
ifstream t2("doctor.txt");

cout<<"Enter name to be displayed: ";
cin>>find;

cout<<endl;
int notFound = 0;
for( j=0;((j<i)||(!t2.eof()));j++)
{
    getline(t2,d[j].dic);

    if(d[j].dic==find)
 {
  notFound = 1;
  cout<<"First name: "<<d[j].dfname<<endl;
  getline(t2,d[j].dlname);
  cout<<"Last name: "<<d[j].dlname<<endl;
  getline(t2,d[j].dqualification);
  cout<<"Qualification: "<<d[j].dqualification<<endl;
  getline(t2,d[j].ic);
  cout<<"IC number: "<<d[j].dic<<endl;
  getline(t2,d[j].dno);
  cout<<"Phone number: "<<d[j].dno<<endl;
 }
 }//for loop
t2.close();
if(notFound == 0){
         cout<<"No Record Found"<<endl;
}
 cout<<"Press any key two times to proceed";
getch();//To hold data on screen
getch();//To hold data on screen
}//case 2

continue;//Control pass to inner loop-2

case '3'://Jump to main
{
break;//inner switch
}//case 3

}//inner switch

break;//inner while
}//inner loop

continue;//control pass to 1st loop
}//outer case 2

 case '3':
{
break;//outer case 3
}//outer case 3
}

}










This is my error

||=== Build file: "no target" in "no project" (compiler: unknown) ===|
C:\Users\Praveen\Documents\programming\praveen.cpp||In function 'int main()':|
C:\Users\Praveen\Documents\programming\praveen.cpp|247|error: no match for 'operator[]' (operand types are 'doctor' and 'int')|
C:\Users\Praveen\Documents\programming\praveen.cpp|249|error: no match for 'operator[]' (operand types are 'doctor' and 'int')|
C:\Users\Praveen\Documents\programming\praveen.cpp|252|error: no match for 'operator[]' (operand types are 'doctor' and 'int')|
C:\Users\Praveen\Documents\programming\praveen.cpp|253|error: no match for 'operator[]' (operand types are 'doctor' and 'int')|
C:\Users\Praveen\Documents\programming\praveen.cpp|254|error: no match for 'operator[]' (operand types are 'doctor' and 'int')|
C:\Users\Praveen\Documents\programming\praveen.cpp|255|error: no match for 'operator[]' (operand types are 'doctor' and 'int')|
C:\Users\Praveen\Documents\programming\praveen.cpp|256|error: no match for 'operator[]' (operand types are 'doctor' and 'int')|
C:\Users\Praveen\Documents\programming\praveen.cpp|257|error: no match for 'operator[]' (operand types are 'doctor' and 'int')|
C:\Users\Praveen\Documents\programming\praveen.cpp|258|error: no match for 'operator[]' (operand types are 'doctor' and 'int')|
C:\Users\Praveen\Documents\programming\praveen.cpp|259|error: no match for 'operator[]' (operand types are 'doctor' and 'int')|
C:\Users\Praveen\Documents\programming\praveen.cpp|260|error: no match for 'operator[]' (operand types are 'doctor' and 'int')|
C:\Users\Praveen\Documents\programming\praveen.cpp|284|error: continue statement not within a loop|
||=== Build failed: 12 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
getline (t2, d[j].dic); d is a simple object of class doctor. You can't use the subscript operator there. If you need more than 1 doctor better create a vector<doctor>
Look at this snippet it may help highlight the errors in your code:
1
2
3
4
5
6
7
8
9
    doctor d;
    for (int i = 1; i < 5; i++)
    {
        // Wrong
       getline(cin, d[i].dfname); // bad code

        // Right
        getline(cin, d.dfname); // This will update the d.dfname 5 times
    }
Topic archived. No new replies allowed.