bool goOn=true ?

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 - is bool goon=true the correct way to do this?

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
  #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;
}Put the code you need help with here.
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
#include <iostream>
#include <string>

using namespace std;

int main() {
	string input, answer;
	while (1) {
 		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;
		cout << "Enter a name: ";
		cin >> input; //this is the line that solved your problem
		if (input == "Crystal") {
			cout << "6/4/1986";
		} else if (input  == "Scott") {
			cout << "10/16/1986";
		} else if (input  == "Sean") {
			cout << "10/11/1983";
		} else if (input  == "Diana") {
			cout << "8/18/1989";
		} else if (input  == "Jara") {
			cout << "8/18/1989";
		}
		cout << endl << endl;
		cout << "Would you like to enter another name: ? Enter y or n: ";
		cin >> answer;
		if (answer!="y" && answer!="Y") {
			break;
		}
	}
	cout << "Thanks for playing" << endl;
	system("pause");
	return 0;
}


the other changes were intended to answer your question "is bool goon=true the correct way to do this?" I personally think this way is neater.
Last edited on
Topic archived. No new replies allowed.