when you input a name the output omit the first character. what to do?

//When you register a patient info and search for your record the first letter of the names omitted. For Ex. lastname: cruz firstname: Zia the output become "CRUZ IA". I dont know why and what to do pls. help i badly need an answer by tomorrow morning so pls. help me

#include <iostream>
#include <fstream>



using namespace std;
void regPatientInfo()

{
string lname, fname, mname, lname2, fname2, mname2, con, dis, cons, depart, ward, blood;
char gender, resp;
int pid, age, month, day, year, month2, day2, year2, height, weight, room, bed, hour, min;

cout<<"\n\t\t--------------- ISKOPITAL ------------------"<<endl;
cout<<"\n\t\t-------------REGISTER THE PATIENT-----------"<<endl;
cout<<" Patient ID:";
cin>>pid;
cout<<" Patient name"<<endl;
cout<<" \tLast Name: ";
cin.ignore();
getline(cin,lname);
cout<<" \tFirst Name: ";
cin.ignore();
getline(cin,fname);
cout<<" \tMiddle Name: ";
cin.ignore();
getline(cin,mname);
cout<<" \n\t\tAge: ";
cin>>age;
.....
....
cout<<" \n\tEnter Another Transaction [Y/N] ? : ";
cin>>resp;
if (resp=='Y')
{
regPatientInfo();
}
else
{
getch();
}


ofstream H("D:\\example.txt",ios::ate|ios::app);
if (H.is_open())
{
H<<pid<<";";
H<< lname <<";"<< fname <<";" << mname <<";";
H<<age<<";";
H<<gender<<";";
H<<weight<<";";
H<<height<<";";
H<<blood<<";";
H<<month <<";"<< day <<";"<< year <<";"<<";";
H<<con<<";";
H<<dis<<";";
H<<cons<<";";
H<<depart<<";";
H<<lname2 <<";"<< fname2 <<";"<< mname2 <<";";
H<<month2 <<";"<< day2 <<";"<< year2 <<";"<<";";
H<< hour <<":"<< min <<";";
H<<ward<<";";
H<<room<<";";
H<<bed<<endl;
H.close();
}
else cout << "Unable to open file";
getch();
}


void search()
{
string spid,pID;
string fname1,lname1,age, wmname,wfname,wlname,wage, wgender, wheight,wweight,wblood,wmonth, wday, wyear,wcontact;
string wdisease,wconsulttype,wdepartment,wfname2,wlname2, wmname2,wmonth2,wday2,wyear2,whour,wmin, wpID, pID1;
string wwardtype,wroomno,wbedno,example;
cout<<"Enter Patient ID: ";
cin>>spid;

ifstream H("example.txt");

if (H.is_open())
{
while ( H.good())
{
getline(H, wlname,' ');
getline(H, wfname,' ');
getline(H, wmname,' ');
...........
getline(H,example);
if (wpID==pID1)
{
cout<< wlname<<"\n";
cout<< wfname<<"\n";
cout<< wmname<<"\n";
cout<< wage<<"\n";
cout<< wgender<<"\n";
cout<< wheight<<"\n";
cout<< wweight<<"\n";
cout<< wblood<<"\n";
cout<< wmonth<<"\n";
cout<< wday<<"\n";
cout<< wyear<<"\n";
cout<< wcontact<<"\n";
cout<< wdisease<<"\n";
cout<< wconsulttype<<"\n";
cout<< wdepartment<<"\n";
cout<< wfname2<<"\n";
cout<< wlname2<<"\n";
cout<< wmname2<<"\n";
cout<< wmonth2<<"\n";
cout<< wday2<<"\n";
cout<< wyear2<<"\n";
cout<< whour<<"\n";
cout<< wmin<<"\n";
cout<< wwardtype<<"\n";
cout<< wroomno<<"\n";
cout<< wbedno<<"\n";
cout<< example<<"\n";
H>>pID; //>>wlname>>wfname>>wmname>>wage>>wgender>>wheight>>wweight>>wblood>>wmonth>>wday>>wyear>>wcontact>>wdisease>>wconsulttype>>wdepartment>>wlname2>>wfname2>>wmname2>>wmonth2>>wday2>>wyear2>>whour>>wmin>>wwardtype>>wroomno>>wbedno;
getch();
}
}
H.close();
}
else
{
cout<<"unable to open file";
}


// if (spid==pID)
// {
// cout<<"no rec found";
// }
}


void billing()
{
string lname3, fname3, mname3;
float dep, phar, medsp, rad, nuc, opRoom, ane, ultra, res, ekg, xray, the, lab, eme, stu, car, cha;
int month3, day3, year3, nday;
char resp;

cout<<"\n\t\t --------------- ISKOPITAL ------------------"<<endl;
cout<<"\n\t\t-------------INFORMATION TO BE RELEASED-----------"<<endl;
cout<<" Patient name"<<endl;
cout<<" \tLast Name:";
cin.ignore();
getline(cin, lname3);
cout<<" \tFirst Name:";
cin.ignore();
getline(cin, fname3);
cout<<" \tMiddle Name:";
cin.ignore();
getline(cin, mname3);
...
..........
..
cout<<"Enter Another Transaction [Y/N]?: ";
cin>>resp;
if (resp=='Y')
{
billing();
}
else
{
getch();
}

ofstream H("D:\\billingInfo.txt",ios::ate|ios::app);
if (H.is_open())
{

H<< lname3 <<";"<< fname3 <<";"<< mname3 <<";";
..
.
H<<month3 <<";"<< day3 <<";"<< year3 <<";"<<endl;
H.close();
}
else cout<<"Unable to open file";
getch();
}

int main ()
{
char i;

cout<<"----------------------------------------"<<endl;
cout<<" Patient's Record- Main Menu"<<endl;
cout<<"----------------------------------------"<<endl;
cout<<" Enter 1 Register a Patient"<<endl;
cout<<" Enter 2 Search a Record"<<endl;
cout<<" Enter 3 Release a Patient "<<endl;
cout<<"----------------------------------------"<<endl;
cout<< "Enter option:";
cin>> i;
switch(i)
{
case '1':
regPatientInfo();
break;
case '2':
search();
break;
case '3':
billing();
break;
default:
cout<<"invalid input"<<endl;
if( i != 1,2,3,4)
{
cout<<"invalid input"<<endl;
break;
}
}
return 0;
getch();

}
closed account (o3hC5Di1)
Hi there,

Please put your code in between [code][/code]-tags.

It seems to me that the problem is here (not just here, throughout the code):

1
2
3
cout<<" \tLast Name: ";
cin.ignore(); //you call this before getting the name
getline(cin,lname);


Try doing cin.ignore() after you got the input: http://www.cplusplus.com/reference/istream/istream/ignore/

All the best,
NwN
Last edited on
it omits the given information. for example last name:torres firsname:zia . the information dont appear
Topic archived. No new replies allowed.