void newaccount()
{
fstream fp;
int nid,id, npw, pw, renid, repw, newaccount=1;
int nscore=0, nunlocked=1, score, unlocked, rank;
fp.open("membership.txt", fstream::in);
if(!fp) cout<<"Unable to open file under input mode!";
else
{
while(!fp.eof() )
{
fp>>id>>pw>>score>>unlocked>>rank;
if(fp.fail()) { break; system("pause");}
}
fp.close();
fp.open("membership.txt", fstream::app) ;
if(!fp) cout<<"Unable to open file under app mode!";
else
{
while(true)
{
cout<<"Please enter your desired Username and Password!"<<endl;
cin>>nid>>npw;
cout<<"Please re-enter your desired Username and Password!"<<endl;
cin>>renid>>repw;
if (nid == renid && npw == repw)
{
cout<<"Congratulations! Your account has been created successfully!"<<endl;
break;
}
elseif (nid != renid || npw!= repw)
{
while(nid != renid || npw!= repw)
{
cout<<"Username and Password do not match each other!"<<endl;
cout<<"Please enter your desired Username and Password!"<<endl;
cin>>nid>>npw;
cout<<"Please re-enter your desired Username and Password!"<<endl;
cin>>renid>>repw;
}
cout<<"Congratulations! Your account has been created successfully!"<<endl;
break;
}
elsebreak;
cout<<endl;
cout<<"Adding a new record:\n";
cout<<nid<<" "<<npw<<" "<<endl;
fp<<nid<<" "<<npw<<" "<<0<<" "<<0<<" "<<9999<<endl;
if(fp.fail()) cout<<"Error encountered while adding data!\n";
else
cout<<"Data added!\n";
}
}
fp.close();
}
}