Part 1:
Write a program that reads a person's name in the format: first name, then middle name or initial, and then last name. The program then outputs the name in the format:
Last_Name, First_Name, Middle_Initial.
For example, the input:
Mary Average User
should proguce the output:
User, Mary A.
The input
Mary A. User
should also produce the output:
User, Mary A.
Part 2:
Your program should allow for users who give no middle name or middle initial. In that case, the output, of course, contains no middle name or initial.
For example, the input:
Mary User
should produce the output:
User, Mary
I just know how to do Part 1... and what I wrote is:
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a,b,c;
cout<<"Please type in your first name, middle name or initial, and then last name:"<<endl;
cin >> a >> b >> c;
cout <<"Your name is:"<<endl<< c <<", " << a <<" " << b[0] <<"." << endl;
return 0;
}
Can anyone help me for Part 2? thanks!!