using the return function

What is the easiest way to return to a point in a program, such as...if I wanted to return to
cout << how many people are in your family?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int fam, age, agetot, stopper ;
double x;
	char yon;
	cout << "This program will determine your family's average age.\n";
	cout << "How many people are in your family?\n";
	cin >> fam ;
	cout << "There are " << fam << " people in your family. Is this correct? Press Y for yes, N for no.\n";
	cin >> yon;
	if ((yon=='Y') || (yon=='y')){
	  cout << "Enter a family member's age, then press enter.\n";
        agetot =0;
        stopper=1;
            while (stopper <= fam){
            cin >> age;
            agetot= agetot + age;
            stopper++;
            };
            x = agetot/fam;
            cout << "Your family's average age is: " << x;
	}
	else if ((yon=='N') || (yon=='n')){
        cout << "Okay, please try again.\n";

1. Wrap repeting part in a loop.
2. Move that part into a separate function (or a series of functions) then p.1.
I should've mentioned, I'm very new to C++, so I have no idea how to do that. and what is p.1?
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
void average_age()
{
	int fam, age, agetot, stopper ;
	double x;
	cout << "How many people are in your family?\n";
	cin >> fam ;
	cout << "There are " << fam << " people in your family. Is this correct? Press Y for yes, N for no.\n";
	char yon;
	cin >> yon;
	if ((yon=='Y') || (yon=='y')){
	  cout << "Enter a family member's age, then press enter.\n";
        agetot =0;
        stopper=1;
            while (stopper <= fam){
            cin >> age;
            agetot= agetot + age;
            stopper++;
            };
            x = agetot/fam;
            cout << "Your family's average age is: " << x;
	}
	else if ((yon=='N') || (yon=='n')){
        cout << "Okay, please try again.\n";
}

int main()
{
	cout << "This program will determine your family's average age.\n";
	char answer;
	do {
		average_age();
		std::cout << "Do you want to run the calculation again?\n";
		std::cin >> answer;
	} while(answer == 'Y' || answer == 'y');
}
thank you for your time and for helping me. Much appreciated!!
Topic archived. No new replies allowed.