i have done different combination and different arrangement of this code for i think that will solve my problem but i only got different errors.....
i'm not having a problem with the first part and the last part of the code.... i think the error occurs in the part when i try to check if the ID number exist......
i'm not sure if a got some wrong syntax..... but i already make sure that there is not...
so, do anyone knows whether this is a syntax problem or an inappropriate arrangement? if it is, can you tell me which line so i can fix it......
here is the function definition of the code.....
void addRec(){
fstream data;
char choice;
int _id;
do{
cls();
cout<<"===== Enter New Record ====="<<endl;
cout<<endl<<endl;
do{
do{
cin.clear();
cin.sync();
cout<<"\nID: ";cin>>_id;
if(cin.fail())
cout<<"You must input a valid integer for the ID number!\n";
}while(cin.fail());
data.open("data.dat", ios::in);
data.read((char*)&e,sizeof e);
if(_id==e.id)
{data.close();
cout<<"ID no. already exist";}
}while(_id==e.id);
e.id=_id;
newline();
cout<<"\nName :\t\t"; gets_s(e.name,50);
cout<<"\nAddress :\t"; gets_s(e.address,50);
cout<<"\nBasic Salary :\t";cin>>e.basic;
cout<<"\nAllowance :\t";cin>>e.allowance;
cout<<"\nDeductions :\t";cin>>e.deduction;
cout<<endl<<endl;
do{
cout<<"S --> Save | C --> Cancel"<<endl;
cin>>choice;
newline();
}while(!(choice=='S' || choice=='s' || choice=='C' || choice=='c'));
}while(!(choice=='S' || choice=='s' || choice=='C' || choice=='c'));
if(choice=='S' || choice=='s'){
data.open("data.dat",ios::out|ios::app);
data.write((char*)&e,sizeof e);
data.close();
cout<<"\nRecord Saved "<<endl<<endl;
}
else if (choice=='C' || choice=='c')
{
cout<<"Record Canceled\n";
}
else
cout<<"Invalid Input\n";
cout<<"Enter another record?"<<endl;
cout<<"Y --> Yes "<<endl;
cout<<"Press any character to return to Menu Options....\n";
cin>>choice;
newline();
if(choice=='Y' || choice=='y')
addRec();
main();
}

New Topic/Question
Reply



MultiQuote




|