Simple Interviewee Program

hello friends, i have a problem regarding a simple interviewee program that i hav created. here is a code of that:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>

using namespace std;

int main()
{
    int age;
    string fName, lName, profession, study, job, residency;
        
    cout << "***************************************************" << endl;
    cout << "*********************Interviewee*******************" << endl;
    cout << "***************************************************" << endl << endl;
    
    cout << "What is your name? ";
    getline(cin, fName);
    
    cout << "What is your father's name " << fName << "? ";
    getline(cin, lName);
    
    cout << "How old are you? ";
    cin >> age;
    
    cout << "Where do you live? ";
    getline(cin, residency);
    
    cout << "what do you do? ";
    getline(cin, profession);
    
    if (profession == "study")
    {
                  cout << "What do you study? ";
                  getline(cin, study);
    }
    else if (profession == "job")
    {
                  cout << "What job do you own? ";
                  getline(cin, job);
    }
    
    cout << "Thank you " << fName << " " << lName << " for your kind attention.\nYou provided that you are " << age << " years old doing " << profession << " in " << residency << endl;
        
    getchar();
    return 0;
}





the problem is that this program compiles good runs good as it ask one by one

What is your name: I type my name here
What is you father's name: I type my fathers name here
How old are you? I type my age here

the problem starts here after

Where do you live? What do you do?

why it doen't hold and move immediately towards the next statement till i type my place of living?

your help will be appreciable!
You can try with this code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <windows.h>

using namespace std;

int main()
{
    int age;
    string fName, lName, profession, study, job, residency;
        
    cout << "***************************************************" << endl;
    cout << "*********************Interviewee*******************" << endl;
    cout << "***************************************************" << endl << endl;
    
    cout << "What is your name? ";
    getline(cin, fName);
    
    cout << "What is your father's name " << fName << "? ";
    getline(cin, lName);
    
    cout << "How old are you? ";
    cin >> age;
    
    cout << "Where do you live? ";
    cin >> residency;
    
    cout << "what do you do? ";
    cin >> profession;
    
    if (profession == "study")
    {
                  cout << "What do you study? ";
                  cin >> study;
    }
    else if (profession == "job")
    {
                  cout << "What job do you own? ";
                  cin >> job;
    }
    
    cout << "Thank you " << fName << " " << lName << " for your kind attention.\nYou provided that you are " << age << " years old doing " << profession << " in " << residency << endl;
    Sleep(2500);
    getchar();
    return 0;
}
hi again,

you basicaaly didn't get me rightly!

i want the program line by line as:

What is your name? my name
What is your father's name? my father's name
How old are you? my age
Where do you live? my place
What do you do? my occupation
n so on

but after asking my age it ask for my place and immediately ask for my occupation why it is so?
i m getting similar result as given below:

What is your name? my name
What is your father's name? my father's name
How old are you? my age
Where do you live? What do you do? my occupation
n so on
Read over this article. It should help.
http://www.cplusplus.com/forum/articles/6046/

This is where your problem lies:
 
cin >> age;


After this is executing, the newline character is still in the stream.
Topic archived. No new replies allowed.