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;
}
elseif ((yon=='N') || (yon=='n')){
cout << "Okay, please try again.\n";
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;
}
elseif ((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');
}