#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string first, last;
int age;
char again ='Y';
ofstream my_file;
while (again =='Y' || again =='y')
{
cout << "\nEnter your first name";
cin >> first;
cout << "\nEnter your last name";
cin >> last;
cout << "\nHow old are you?";
cin >> age;
if (my_file) {
my_file.open("name_age.txt", ios::app); my_file << first << endl;
my_file << last << endl;
my_file << age << endl;
my_file.close(); }
else {
cout << "\nAn error occurred while opening the file\n";
}
cout << "\nDo you want to input another name?";
cin >> again;
}
return 0;
}