0

Output of the programthe program is correct but after executing all statements when its coming to the class graduate, compiler is not taking the input from me for memid instead it jumps to next statement.

#include<iostream>
#include<conio.h>
using namespace std;
class member{
protected:
    string memid,memname;
public:
    void get_info(){
        cout<<"\nEnter Member Id:\t";getline(cin,memid);
        cout<<"\nEnter Member Name:\t";getline(cin,memname);
    }
    void show_info(){
        cout<<"\nMember Id :\t "<<memid;
        cout<<"\nMember Name:\t"<<memname; 
    }
};
class employee:public member{
protected:
    string jobtitle,location;
public:
    void get_info(){
         member::get_info();
        cout<<"\nEnter job title: \t";getline(cin,jobtitle);
        cout<<"\nEnter Location: \t";getline(cin,location);
    }
    void show_info(){
         member::show_info();
        cout<<"\nJob Title:\t"<<jobtitle;
        cout<<"\nLocation:\t"<<location;
    }
};
class student:public member{
protected:
    string institution;
public: 
    void get_info(){
         member::get_info();
        cout<<"\nEnter institution name:\t";getline(cin,institution);
    }
    void show_info(){
         member::show_info();
        cout<<"\nInstitution Name is:\t"<<institution;
    }
};
class undergraduate:public student{
protected:
    int age;
public:
    void get_info(){
         student::get_info();
        cout<<"\nEnter age:\t";cin>>age;
    }
    void show_info(){
         student::show_info();
        cout<<"\nAge:\t"<<age;
    }
};
class graduate:public student{
protected: 
    string department;
public:
    void get_info(){
         student::get_info();
        cout<<"\nEnter Department Name:\t";getline(cin,department);
    }
    void show_info(){
         student::show_info();
        cout<<"\nDepartment is:\t"<<department;
    }
 };
int main(){
employee e1;
undergraduate u1;
graduate g1;
cout<<"Enter Information of Employees:";
e1.get_info();
cout<<"\nHere is the Information of Employees:";
e1.show_info();
cout<<"\nEnter Information of Undergraduate Student:";
u1.get_info();
cout<<"\nHere is the Information of Undergraduate Student:";
u1.show_info();
cout<<"\nEnter Information of Post graduate students:";
g1.get_info();
cout<<"\nHere is the Information of Post graduate Student:";
g1.show_info();
getch();
}
  • Please include the actual and expected output in the question body, as text (copy-pasted). – Some programmer dude Nov 03 '16 at 09:07
  • The problem is easy to solve though, and happens because your reading an integer previously. What happens then is that the newline is still left in the input buffer for the next `getline` call. You might want to read about the [`ignore`](http://en.cppreference.com/w/cpp/io/basic_istream/ignore) function for a way to solve your problem. – Some programmer dude Nov 03 '16 at 09:09

0 Answers0