I have a question asking me to prompt a user for first and last names. Declare a third array to hold last and first name separated by a comma and a space. Use loops to iterate through the names one character at a time, storing them into the full name array.
It sound easy enough, but I'm having so much trouble with it. I've tried multiple ways to do it, even ways the question doesn't ask for, like strncpy or memcpy or strncat. Maybe I'm just not understanding correctly.
This is what I currently have:
char FirstName[15];
char LastName[15];
char FirstLast[30];
cout << "Enter your first name: ";
cin >> FirstName;
cout << "Enter your last name: ";
cin >> LastName;
for (int i = 0; i<30; i++)
{
if (i < 15) {
FirstLast[i] = LastName[i];
}
else {
FirstLast[i] = FirstName[i - 5];
}
}
cout << FirstLast;
Thanks for any help.