user defined. I'm not sure why is my prog not working when I have declared everything needed.

I could not compute my member.
Please guide me.


#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
void computeMember();
using namespace std;

int main()
{
int option;
string member;
cout<<"Welcome to our hotel service\n";
cout<<"1. Member"<<endl;
cout<<"2. Non member"<<endl;
cout<<"Please enter your option."<<endl;
cin>>option;
if (option==1)
member=computeMember();
else if (option==2)
computeNMember();
else
cout<<"Invalid choice!";
system("pause");
return 0;
}
void computeMember()
{
string line, member,name,nationality,contactN,contact,DOB,birthday;
ifstream inFile;
inFile.open("list.txt");
if (!inFile)
{
cout<<"unable to open file"<<endl;
}
cout<<"Please enter DOB [ddmmyyyy]: ";
cin>>birthday;
//print header
size_t pos;
while(inFile.eof())
{
//reading data in textfile
getline(inFile,line);
pos=line.find(birthday);
if(pos!=string::npos)
{
cout<<left;
cout<<setw(15)<<"Name"<<setw(15)<<"Nationality"<<setw(15)<<"contact No"<<setw(15)<<"D.O.B"<<endl; //print header
inFile>>name>>nationality>>contactN>>DOB;
cout<<setw(15)<<name<<setw(15)<<nationality<<setw(15)<<contactN<<setw(15)<<DOB<<endl;
break;
}
}
system("pause");
return member;
}
Last edited on
1. Edit your post to add the code tags. See http://www.cplusplus.com/articles/jEywvCM9/

2. Please explain the "not working" in detail.
Topic archived. No new replies allowed.