Hello
I can't understand why 1st cin for Enter Name is skipped out of 3 cin statements in getData function in Teachers class other 2 cin statements are accepting input- Here is code -

    #include <iostream.h>
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    class Teachers
    {
      private:
          char staff[20];
          char post[20];
          char address[30];
      public:
          void getData()
          {
          cout<<"Enter Name";
          cin.getline(staff,20);
          cout<<"Enter Post";
          cin.getline(post,20);
          cout<<"Enter Address";
          cin.getline(address,30);
          }
    };
    class Regular:public Teachers
    {
        private:
        int HRA, DA, Basic, cHRA, cDA, Gross, Net;
        public:
        void getAllData()
        {
            getData();
            cout<<"Enter Basic Pay";
            cin>>Basic;
            cout<<"Enter HRA";
            cin>>HRA;
            cout<<"Enter DA";
            cin>>DA;
        }
    };
    class Contractual:public Teachers
    {
        private:
        int Wages;
        int WorkingDay;
        int CCL;
        int ML;
        int cWages;
        public:
        void getAllData()
        {
            getData();
            cout<<"Enter Daily wages";
            cin>>Wages;
            cout<<"Enter Working Days";
            cin>>WorkingDay;
        }
    };
    int main()
    {
      Regular reg;
      Contractual con;
      char cata='R';
      clrscr();
      cout<<"Enter the catagory for calculation ";
      cin>>cata;
      if(cata=='R' || cata=='r')
      {
        reg.getAllData();
      }
      else
      {
          con.getAllData();
      }
      return 0;
    }

Please show me the way
Regards

I'm guessing you didn't read any of the stickies, given that one of them addresses your exact problem.

Thank you for consideration, I gone through many documentation. But my conser is if this code is running perfectly (PERFECT CODE getline.cpp) in turbo C++

    #include <string.h>
    #include <iostream.h>
    #include <conio.h>
    class xyz
    {
    private:
     char a[20];
     char b[10];

    public:
       void getdata()
       {
    cout<<"Enter First Name";
     cin.getline(a,20);
    cout<<"Enter Second Name";
     cin.getline(b,10);
      cout << a;
      cout << b;
       }
    };
    class sub:public xyz
    {
         public:
             void getALL()
             {
                   getdata();
             }
    };
    int main() {

     sub S;
     clrscr();
     S.getALL();
      return 0;
    }

THEN WHY THE ABOVE CODE IS NOT RUNNING WHAT IS THE PROBLEM. I am testing both the code on turbo C++. I am totally confused

Got the answer thank youdeception for guidance I used cin.ignore()

commented: Kudos for figuring it out. +12
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.