Every time I try to run this it asks me for the name and once I hit enter It keeps running. It does not let me enter a age or ask if I want to run this program again.
Code:
int main()
{
char name[15];
int age[3];
char answer = 'y'||'Y';
int i = 0;
while(answer=='y'||'Y')
{
cout << "Enter name: ";
cin >> name[i];
cout <<endl;
cout << "Enter Age: ";
cin >> age[i];
cout <<endl;
cout << "Would you like to add another person? (Y/N)";
cin >> answer;
cout <<endl;
}
I found a piece of code using vectors that works but I do not know how to implement it so It will prompt a user to enter a name and age until the user is done entering data.
Code:
const int NUM_PERSONS = 5;
vector<string> names(NUM_PERSONS);
vector<int> ages(NUM_PERSONS);
for (int i = 0; i < names.size(); i++)
{
cout << "Enter name: ";
getline (cin, names[i]);
cout << "Age: ";
cin >> ages[i];
cin.get();
}