Array Output
I 'm trying to print someone's first initial of a middle name in my program For example: user input-John Henry Holiday program output- Holiday, Henry H. #include <iostream> #include <string> using namespace std; string capitalize(string name); string lastNameFirst(string name[]); int main() { string userName[3]; cout << "First name: "; getline(cin, userName[0]); cout << "Middle name: "; getline(cin, userName[1]); cout << "Last name: "; getline(cin, userName[2]); cout << "Your name is: " << lastNameFirst(userName) << endl; system("pause"); return 0; } string capitalize(string name) { int i = 0; int isSpace = 0; if (!name.empty()) { name[0] = toupper(name[0]); } for (i = 1; i < name.length(); i++) { if (name[i] == ' ') { isSpace = 1; } else { if (isSpace) { name[i] = toupper(name[i]); isSpace = 0; } else { name[i] = tolower(name[i]); } } } return name; } string lastNameFirst(string name[]) { string userName = capitalize(name[2]) + ", " + capitalize(name[0]) + " " + capitalize(name[1]); return userName; }