the aim of this program is to create a record of 20 members inputted by the user st the phone number is stored in 3 different parts e.g. 011-234-7891 where 011 is area code 234 is exchange and 7891 is numbr...every record must have a member id and member name and number in this format........ and the phone number should be in a different class called phone containing area code,exchange and number as variables
also we have to provide an option to the user for searching the records by member name or phone number.. I was able to do the searching by member name ... but for searching by member phone number i am getting an error.... the first member is shown every time searching is done by phone number .. please tell me wher i have gone wrong...

p.s. i know this is a very simple program but i just cannot find where i have done the mistake.. im giving the name of the classes used and only expanded the member functions which are required for checking the records by phone number

#include<iostream>
#include<iomanip>
#include<cstring>

using namespace std;

class phone
{
    public:
    int area_code,exchange,numbr;
    void get_number();

};

class member
{
    int member_id;
    char membername[50];
    phone number;
    public:
    void get_memberinfo();
    void show_memberinfo();
    int check_membername(char *n);
    int check_num(int &,int &,int &);
};

member record[20];
char *n;

void phone :: get_number()
{
}

void member :: get_memberinfo()
{
}

void member :: show_memberinfo()
{
}

int member :: check_membername(char *n)
{
    

}

int member :: check_num(int &a,int &b,int &c)
{
    if (number.area_code==a && number.exchange==b &&number.numbr==c)
                return 0;
    else
                return 1;
       
}


void searchby_name()
{
  
}

void searchby_numbr()
{
    int num1,num2,num3,i,flag=1,loc;
    char c;
    cout<<"Enter phone number in the format \'areacode - exchange - number (003 - 2442 - 6523)\' "<<endl;
    cin>>num1>>c>>num2>>c>>num3;
    for(i=0;i<3;i++)
    {
        if (record[i].check_num(num1,num2,num3)==0);
        {
            flag=0;
            loc=i;
            break;
        }
    }
    if (flag==0)
    {
        cout<<"Member found"<<endl;
        cout<<"Member id"<<setw(25)<<"Member Name"<<setw(25)<<"Phone number"<<endl;
        record[loc].show_memberinfo();
        flag=1;
    }
    else
    cout<<"Member not found"<<endl;
    i=0;loc=0;
    cin.clear();
}



int main()
{

   CODE for entering and printing the members

if(choice==1)
                searchby_name();
    return 0;
}

Here is mistake in line 96.
CODE CODE for entering and printing the members????
There is no code for entering and printing the members.
Thank you.

There are a couple of things wrong at a basic level.

1. Don't store phone numbers as Integers. Here's why 003-2442-0964
When you get that back you will actually get: 3-2442-964 which is incorrect. So you should store them as a string, ideally.

2. Although not "incorrect" this is a little confusing. In your check_num method, you return 0 for success and 1 for failure. In comparison statements (if, while etc.) FALSE is represented by 0 and TRUE by 1. It would make more sense, in my opinion to have 1 as "found" and 0 as "not found".

Why it only displays the first one...I think you should set a debug point in your check_num method at the "return 0" statement and check the values that you're getting. When you go back *out* of the method, it will also tell you what iteration (array location) you're at. This way you should know what's happening.

Your code in check_num() is fine (other than not maintaining leading zeroes, as Ketsuekiame pointed out). Instead you have a subtle error on line 71. Can you spot it yourself?

While it doesn't matter, since you're not changing a, b or c within check_num(), you don't need to recover the values back in the caller. Therefore you don't need to pass them by reference, and line 48 can be int member :: check_num(int a,int b,int c) .

Thank you for the replies... and i understand your point ketsukiame.. it was very useful and i was able to correct my code....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.