the program requires to register then search it and last it release the record .

there is still an error, it doesnt function well.

#include <iostream>
#include <fstream>
#include<conio.h>
#include<cstring>
#include<string.h>
using namespace std;
string lname, fname, mname, lname2, fname2, mname2, contact, disease, consult, department, ward, blood, slname,sfname, smname;
char gender;
int age, month, day, year, month2, day2, year2, height, weight, room, bed, hour, minutes;
int main();
{
int register()
{

cout<<"\n\t\t--------------- ISKOPITAL ------------------"<<endl;
cout<<"\n\t\t-------------REGISTER THE PATIENT-----------"<<endl;
cout<<" Patient name"<<endl;
cout<<" \tLast Name:";
cin>>lname;
cout<<" \tFirst Name:";
cin>>fname;
cout<<" \tMiddle Name:";
cin>>mname;
cout<<" \n\t\tAge:";
cin>>age;
cout<<" \n\tGender [F/M]:";
cin>>gender;
cout<<" \n\tWeight [kg]:";
cin>>weight;
cout<<" \n\tHeight [cm]:";
cin>>height;
cout<<" \n\tBlood Type:";
cin>>blood;
cout<<" \n\tDate of Birth";
cout<<" \n\t\t\tMonth:";
cin>>month;

cout<<" \tDay:";
cin>>day;
cout<<" \tYear:";
cin>>year;
cout<<" \n\tContact No.:";
cin>>contact;
cout<<" \n\tMedical History";
cout<<" \n\t\t\tDisease:";
cin>>disease;
cout<<" \n\tAppointment Details";
cout<<" \n\t\t\tConsultation type:";
cin>>consult;
cout<<" \tDepartment:";
cin>>department;
cout<<" \tConsultant Doctor";
cout<<" \n\t\t\t\tLast Name:";
cin>>fname2;
cout<<" \tFirst Name:";
cin>>lname2;
cout<<" \tMiddle Name:";
cin>>mname2;
cout<<" \n\tDate of Admission";
cout<<" \n\t\t\tMonth:";
cin>>month2;
cout<<" Day:";
cin>>day2;
cout<<" Year:";
cin>>year2;
cout<<" \n\tTime of Admission";
cout<<" \n\t\t\tHour:";
cin>>hour;
cout<<" \tMinutes:";
cin>>minutes;
cout<<" \n\tWard Type [Public/Private]:";
cin>>ward;
cout<<" \n\tRoom No.:";
cin>>room;
cout<<" \n\tBed No.:";
cin>>bed;
}

ofstream H("D:\\example.txt",ios::ate|ios::trunc);
if (H.is_open())
{
H<<"\n\t\t--------------- ISKOPITAL ------------------"<<endl;
H<<"\n\t\t-------------REGISTER THE PATIENT-----------"<<endl;
H<<"----------------------------------------------------------------------"<<endl;
H<<"| Patient Name :"<< lname <<" "<< fname <<" "<< mname <<endl;
H<<"| Age :"<<age<<endl;
H<<"| Gender :"<<gender<<endl;
H<<"| Weight :"<<weight<<endl;
H<<"| Height :"<<height<<endl;
H<<"| Blood Type :"<<blood<<endl;
H<<"| Date of Birth :"<< month <<" "<< day <<" "<< year <<" "<<endl;
H<<"| Contact No. :"<<contact<<endl;
H<<"| Disease :"<<disease<<endl;
H<<"| Consultation Type :"<<consult<<endl;
H<<"| Department :"<<department<<endl;
H<<"| Consultant Doctor :"<< lname2 <<" "<< fname2 <<" "<< mname2 <<endl;
H<<"| Date of Admission :"<< month2 <<" "<< day2 <<" "<< year2 <<" "<<endl;
H<<"| Time of Admission :"<< hour <<":"<< minutes <<endl;
H<<"| Ward Type :"<<ward<<endl ;
H<<"| Room No. :"<<room<<endl;
H<<"| Bed No. :"<<bed<<endl;
H<<"----------------------------------------------------------------------";

H.close();
}
else cout << "Unable to open file";
getch();
return 0;

int search()
{
Cout<<"Enter Patient first name: ";
cin>> fname;
Cout<<"Last name: ";
cin>>lname;
cout<<"age: ";
ifstream H("example.txt");
while (H)
{
getline(H, wfname, ';');
getline(H, wlname, ';');
getline(H, wname,';');
getline(H,wheight,';');
getline(H,wweight,';');
getline(H,wblood,';');
getline(H,wdbirth,';');
getline(H,wcontact,';');
getline(H,wdisease,';');
getline(H,wconsulttype,';');
getline(H,wdepartment,';');
getline(H,wconsultdoc,';');
getline(H,wdadmission,';');
getline(H,wtadmission,';');
getline(H,wwardtype,';');
getline(H,wroomno,';');
getline(H,wbedno,';');
getline(H,example);
if (wfname==fname && wlname==wlname && wage==age)
{
insert whatever
return 0;
}
}
cout<<"no rec found";
}
int release()
{
cout<<"\n\t\t--------------- ISKOPITAL ------------------"<<endl;
cout<<"\n\t\t-------------INFORMATION TO BE RELEASED-----------"<<endl;
cout<<" Patient name"<<endl;
cout<<" \tLast Name:";
cin>>lname;
cout<<" \tFirst Name:";
cin>>fname;
cout<<" \tMiddle Name:";
cin>>mname;
cout<<" \n\t\Medical Record:";
cin>>record;
cout<<" \n\tX-ray Record:";
cin>>xray;
cout<<" \n\tPhysical Theraphy:";
cin>>theraphy;
cout<<" \n\tLab/Pathology slides:";
cin>>slides;
cout<<" \n\tEmergency Record:";
cin>>emergency;
cout<<" \n\tNeuro/Sleep Studies:";
cin>>studies;
cout<<" \n\tCardilogy:";
cin>>cardiology;
cout<<" \n\tSpecify Dates of treatment";
cout<<" \n\t\t\tMonth:";
cout<<" Day:";
cin>>day;
cout<<" Year:";
cin>>year;
cout<<" \n\tPayment:";



ofstream H("D:\\example2.txt",ios::ate|ios::trunc);
if (H.is_open())
{
H<<"\n\t\t--------------- ISKOPITAL ------------------"<<endl;
H<<"----------------------------------------------------------------------"<<endl;
H<<"| Patient Name :"<< lname <<" "<< fname <<" "<< mname <<endl;
H<<"| Medical Record :"<< record <<endl;
H<<"| X-ray Record :"<< xray <<endl;
H<<"| Physical Theraphy :"<< theraphy <<endl;
H<<"| Lab/ Pathology Slides :"<< slides << endl;
H<<"| Emergency Record :"<< emergency <<endl;
H<<"| Neuro/Sleep Studies :"<< studies <<endl;
H<<"| Cardiology :"<< cardiology <<endl;
H<<"| Date of Treatment :"<< month <<" "<< day <<" "<< year <<" "<<endl;
H<<"----------------------------------------------------------------------";

H.close();
}
else cout << "Unable to open file";
getch();
return 0;
}
}
Last edited on
there is still an error,

What do you mean? What error?

it doesnt function well.

What do you mean? In what way doesn't it function well?

How can you expect us to help you, when you write such vague, meaningless statements?

EDIT: And use code tags when posting code. Can't you see that that's what other people do when they post here?
Last edited on
Well, the code as is does not compile. You may want to look at your compiler errors as they will get it to run at least... then ask what you want to know.

Big issues with syntax as far as I can see at several parts including your main function
Alright well I don't want to get into the grisly details but here goes nothing.

First of all, the original version with code tags:
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
#include <iostream>
#include <fstream>
#include<conio.h>
#include<cstring>
#include<string.h>
using namespace std;
string lname, fname, mname, lname2, fname2, mname2, contact, disease, consult, department, ward, blood, slname,sfname, smname;
char gender;
int age, month, day, year, month2, day2, year2, height, weight, room, bed, hour, minutes;
int main();
{
int register()
{

cout<<"\n\t\t--------------- ISKOPITAL ------------------"<<endl;
cout<<"\n\t\t-------------REGISTER THE PATIENT-----------"<<endl;
cout<<" Patient name"<<endl;
cout<<" \tLast Name:";
cin>>lname;
cout<<" \tFirst Name:";
cin>>fname;
cout<<" \tMiddle Name:"; 
cin>>mname;
cout<<" \n\t\tAge:";
cin>>age;
cout<<" \n\tGender [F/M]:";
cin>>gender;
cout<<" \n\tWeight [kg]:";
cin>>weight;
cout<<" \n\tHeight [cm]:";
cin>>height;
cout<<" \n\tBlood Type:";
cin>>blood;
cout<<" \n\tDate of Birth";
cout<<" \n\t\t\tMonth:";
cin>>month;

cout<<" \tDay:";
cin>>day;
cout<<" \tYear:";
cin>>year;
cout<<" \n\tContact No.:";
cin>>contact;
cout<<" \n\tMedical History";
cout<<" \n\t\t\tDisease:";
cin>>disease;
cout<<" \n\tAppointment Details";
cout<<" \n\t\t\tConsultation type:";
cin>>consult;
cout<<" \tDepartment:";
cin>>department;
cout<<" \tConsultant Doctor";
cout<<" \n\t\t\t\tLast Name:";
cin>>fname2;
cout<<" \tFirst Name:";
cin>>lname2;
cout<<" \tMiddle Name:";
cin>>mname2;
cout<<" \n\tDate of Admission";
cout<<" \n\t\t\tMonth:";
cin>>month2;
cout<<" Day:";
cin>>day2;
cout<<" Year:";
cin>>year2;
cout<<" \n\tTime of Admission";
cout<<" \n\t\t\tHour:";
cin>>hour;
cout<<" \tMinutes:";
cin>>minutes;
cout<<" \n\tWard Type [Public/Private]:";
cin>>ward;
cout<<" \n\tRoom No.:";
cin>>room;
cout<<" \n\tBed No.:";
cin>>bed;
}

ofstream H("D:\\example.txt",ios::ate|ios::trunc); 
if (H.is_open())
{
H<<"\n\t\t--------------- ISKOPITAL ------------------"<<endl;
H<<"\n\t\t-------------REGISTER THE PATIENT-----------"<<endl;
H<<"----------------------------------------------------------------------"<<endl;
H<<"| Patient Name :"<< lname <<" "<< fname <<" "<< mname <<endl;
H<<"| Age :"<<age<<endl;
H<<"| Gender :"<<gender<<endl;
H<<"| Weight :"<<weight<<endl;
H<<"| Height :"<<height<<endl;
H<<"| Blood Type :"<<blood<<endl;
H<<"| Date of Birth :"<< month <<" "<< day <<" "<< year <<" "<<endl;
H<<"| Contact No. :"<<contact<<endl;
H<<"| Disease :"<<disease<<endl;
H<<"| Consultation Type :"<<consult<<endl;
H<<"| Department :"<<department<<endl;
H<<"| Consultant Doctor :"<< lname2 <<" "<< fname2 <<" "<< mname2 <<endl;
H<<"| Date of Admission :"<< month2 <<" "<< day2 <<" "<< year2 <<" "<<endl; 
H<<"| Time of Admission :"<< hour <<":"<< minutes <<endl;
H<<"| Ward Type :"<<ward<<endl	;
H<<"| Room No. :"<<room<<endl;
H<<"| Bed No. :"<<bed<<endl; 
H<<"----------------------------------------------------------------------";

H.close();
}
else cout << "Unable to open file";
getch();
return 0;

int search() 
{
Cout<<"Enter Patient first name: ";
cin>> fname;
Cout<<"Last name: ";
cin>>lname;
cout<<"age: ";
ifstream H("example.txt");
while (H)
{
getline(H, wfname, ';');
getline(H, wlname, ';');
getline(H, wname,';');
getline(H,wheight,';');
getline(H,wweight,';');
getline(H,wblood,';');
getline(H,wdbirth,';');
getline(H,wcontact,';');	
getline(H,wdisease,';');
getline(H,wconsulttype,';');
getline(H,wdepartment,';');
getline(H,wconsultdoc,';');
getline(H,wdadmission,';');
getline(H,wtadmission,';');
getline(H,wwardtype,';');
getline(H,wroomno,';');
getline(H,wbedno,';');
getline(H,example);
if (wfname==fname && wlname==wlname && wage==age)
{
insert whatever
return 0;
}
}
cout<<"no rec found";
}
int release()
{
cout<<"\n\t\t--------------- ISKOPITAL ------------------"<<endl;
cout<<"\n\t\t-------------INFORMATION TO BE RELEASED-----------"<<endl;
cout<<" Patient name"<<endl;
cout<<" \tLast Name:";
cin>>lname;
cout<<" \tFirst Name:";
cin>>fname;
cout<<" \tMiddle Name:"; 
cin>>mname;
cout<<" \n\t\Medical Record:";
cin>>record;
cout<<" \n\tX-ray Record:";
cin>>xray;
cout<<" \n\tPhysical Theraphy:";
cin>>theraphy;
cout<<" \n\tLab/Pathology slides:";
cin>>slides;
cout<<" \n\tEmergency Record:";
cin>>emergency;
cout<<" \n\tNeuro/Sleep Studies:";
cin>>studies;
cout<<" \n\tCardilogy:";
cin>>cardiology;
cout<<" \n\tSpecify Dates of treatment";
cout<<" \n\t\t\tMonth:";
cout<<" Day:";
cin>>day;
cout<<" Year:";
cin>>year;
cout<<" \n\tPayment:";



ofstream H("D:\\example2.txt",ios::ate|ios::trunc); 
if (H.is_open())
{
H<<"\n\t\t--------------- ISKOPITAL ------------------"<<endl;
H<<"----------------------------------------------------------------------"<<endl;
H<<"| Patient Name :"<< lname <<" "<< fname <<" "<< mname <<endl;
H<<"| Medical Record :"<< record <<endl;
H<<"| X-ray Record :"<< xray <<endl;
H<<"| Physical Theraphy :"<< theraphy <<endl;
H<<"| Lab/ Pathology Slides :"<< slides << endl;
H<<"| Emergency Record :"<< emergency <<endl;
H<<"| Neuro/Sleep Studies :"<< studies <<endl;
H<<"| Cardiology :"<< cardiology <<endl;
H<<"| Date of Treatment :"<< month <<" "<< day <<" "<< year <<" "<<endl; 
H<<"----------------------------------------------------------------------";

H.close();
}
else cout << "Unable to open file";
getch();
return 0;
}
}
Some pretty massive problems obviously.

I'm gonna start with the small ones first in hopes that they were typos.

1. It's cout not Cout

1
2
3
Cout<<"Enter Patient first name: ";
cin>> fname;
Cout<<"Last name: "; //It's cout not Cout. C++ is case sensitive 


2. Random Semicolon
int main(); // I have no idea why there's a semicolon there

3. Never declared all the wblahblah string& str...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
getline(H, wfname, ';');
getline(H, wlname, ';');
getline(H, wname,';');
getline(H,wheight,';');
getline(H,wweight,';');
getline(H,wblood,';');
getline(H,wdbirth,';');
getline(H,wcontact,';');	
getline(H,wdisease,';');
getline(H,wconsulttype,';');
getline(H,wdepartment,';');
getline(H,wconsultdoc,';');
getline(H,wdadmission,';');
getline(H,wtadmission,';');
getline(H,wwardtype,';');
getline(H,wroomno,';');
getline(H,wbedno,';');
getline(H,example);
if (wfname==fname && wlname==wlname && wage==age)


4. Line 144 Missing else
cout<<"no rec found";

should be:
else cout<<"no rec found";

5. Never declared record

1
2
string lname, fname, mname, lname2, fname2, mname2, contact, disease, consult, department, ward, blood, slname,sfname, smname; // need to add in record
// as well as all the w...s 


6. Messed up "search" function
This function is really screwy. To fix it I would first do suggestion two under topic 3 below. Change the type to void.
instead of:
int search_function()//don't forget to fix the names

do:
void search_function()

Now get rid of the return on line 141.
Change the logic of lines 138-145 from:
1
2
3
4
5
6
7
8
if (wfname==fname && wlname==wlname && wage==age)
{
insert whatever
return 0;
}
}
cout<<"no rec found";
}


to:
1
2
3
4
5
6
7
if(wfname==fname && wlname==wlname && wage==age)
            {
               insert whatever; // This doesn't do what you think it does...
             }
                else cout<<"no rec found.";
     }
}


so the function will something like this:
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
void search_function()
        {
            cout<<"Enter Patient first name: ";
            cin>> fname;
            cout<<"Last name: ";
            cin>>lname;
            cout<<"age: ";
            ifstream H("example.txt");

            while (H)
            {
                getline(H, wfname, ';'); // These wfname, wlname, wect. were never declared...
                getline(H, wlname, ';');
                getline(H, wname,';');
                getline(H,wheight,';');
                getline(H,wweight,';');
                getline(H,wblood,';');
                getline(H,wdbirth,';');
                getline(H,wcontact,';');
                getline(H,wdisease,';');
                getline(H,wconsulttype,';');
                getline(H,wdepartment,';');
                getline(H,wconsultdoc,';');
                getline(H,wdadmission,';');
                getline(H,wtadmission,';');
                getline(H,wwardtype,';');
                getline(H,wroomno,';');
                getline(H,wbedno,';');
                getline(H,example);

                    if (wfname==fname && wlname==wlname && wage==age)
                    {
                        insert whatever; // this doesn't do what you think it does...
                        
                    }
                    else cout<<"no rec found";
            }
        }


Now for some of the more devastating issues

1. Your design is flawed. One way to learn to design better is to look at other people's code. This forum has many brilliant examples of good code (and plenty examples of bad code too...).

2. Even with all the changes I suggested above note that your code still won't even compile let alone run like you want it. There are a few ways to go from here but before you see them you really should get through the very detailed tutorial available in the documentation tab of this website.

3. Assuming that you've done that I would suggest that you:

First, take all of your functions out of int main() and put them into a class. (if you don't know what that is you didn't read the tutorial). From there you can just call the functions in your main functions.

Second, change the types of all of your functions to void. This will fix many problems in your design (such as all the random returns that return 0)

Third, instead of doing the full declarations in the class you can simply do a prototype declaration in the class, and then do the full declarations below but still outside of the main function

Fourth, come up with some sort of system to call the functions, it could be logic based but the design is really by choice. Hell, you could just call them all back to back to back if you wanted to.

4. It will take a lot more work to get this program up and running but in the future if you start with good practices it will be a lot easier to fix. Also, don't post code without code tags. Don't post help threads without questions, because as you can see, "a few suggestions" very quickly turns into open heart surgery.

I know it seems like a lot and it is, but as Ben Parker once said "with great power comes great responsibility" so don't abuse the forums, but also don't give up.

Good luck,
Sean
Last edited on
Topic archived. No new replies allowed.