Hi I have a problem with an input line in my code. When it should ask for the input for "name" it skips over it and goes to the imput for "school". What am I missing.
Input screen
-------------------
Title: Manager
Number: 21
Name: School: DeVry //this is where the problem is
Degree: BSC
Output screen
-------------------
Title: Manager
Number: 21
Name: //see, it skipped the imput
School: DeVry
Degree: BSC
Press any key to continue
This is my code:
--------------------------
Code:
#include<iostream.h>
#include<string.h>
#include<conio.h>
class Student
{
private:
char school[20];
char degree[20];
public:
void getData();
void putData();
};
class Employee
{
private:
char name[20];
int num;
public:
void getData();
void putData();
};
class Manager
{
private:
char title[20];
Employee em;
Student st;
public:
void getData();
void putData();
};
void Student::getData()
{
cout<<"School: ";
cin.getline(school, 20, '\n');
cout<<"Degree: ";
cin.getline(degree, 20, '\n');
}
void Student::putData()
{
cout<<"School: "<<school<<endl;
cout<<"Degree: "<<degree<<endl;
}
void Employee::getData()
{
cout<<"Number: ";
cin>>num;
cout<<"Name: "; //THIS IS THE PROBLEM
cin.getline(name, 20, '\n');
}
void Employee::putData()
{
cout<<"Number: "<<num<<endl;
cout<<"Name: "<<name<<endl;
}
void Manager::getData()
{
cout<<"Title: ";
cin.getline(title, 20, '\n');
em.getData();
st.getData();
}
void Manager::putData()
{
cout<<"Title: "<<title<<endl;
em.putData();
st.putData();
}
void main (void)
{
Manager m;
m.getData();
m.putData();
return;
}
Code tags added by Kermi3