bool goOn=true question

Hello, I've written a program where I ask for a name which I've given a list of name for and then I return their birthdate. I then ask the user if they would like to enter another name for a birthdate but this is where I can't figure out how to do it? When I run the code below it asks for a name, it displays their birthday - it asks if they want to enter another name and when I reply y - it starts the program again but doesn't let me enter another name it prompts the user if they wanna run the program again? I'm lost at this point.
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
 
 #include<iostream>
#include<string> // gives you string functions
#include <cstdlib>
#include<ctime>

using namespace std;
char answer;


int main()


{
	
bool goOn=true;
while(goOn)

 {
 	cout<< "Programmer: Edgar" << endl;
    cout<< "Program name: Family birthday" << endl;
    cout<< "Program birthdate: 8/15/2013" <<endl << endl  <<endl << endl;
 	
 	cout << "Type a Name below as shown & I will give you their birthdate: " <<endl;
 	cout << "Crystal Sean Scott Diana Jara" <<endl <<endl;
 	
 	
    string input;
    cout << "Enter a name: ";
    getline(cin, input);
      	if (input == "Crystal")
  {
  	cout<< "6/4/1986";
  }
  if (input  == "Scott")
  {
  	cout<< "10/16/1986";
  }
  
  if (input  == "Sean")
  {
  	cout<< "10/11/1983";
}
if (input  == "Diana")
  {
  	cout<< "8/18/1989";
  }
  if (input  == "Jara")
  {
  	cout<< "8/18/1989";
  }
  cout << endl << endl;
  
  cout<<"Would you like to enter another name: ? Enter y or n: ";
  char answer;
  cin>>answer;
 
 if(answer!='y')
 
 
 {
 goOn=false;
 cout<<"thanks for playing!"<<endl;
 } 
 
 }
 return 0;
}
change getline(cin, input);
with cin >> input;

since there might still be '\n' in the stream so getline kinda take that
because the last command before your getline is cin>>answer; which only take the char but not the enter ('\n') therefore the '\n' goes to the next input which is your getline and it takes it as if it's the input

why do you use get line anyway ?
You only want a single name without space
Thanks - that did the trick. I actually copied it from another piece of code (I'm still learning the differences between the two)
Topic archived. No new replies allowed.