I'm working on a problem where the user inputs the first name, middle name and last name and should produce the output, last name, first name then midde initial.
example:
input: John Smith Doe
output: Doe, John S.
the program should also work even if the user does not put the middle name.
example:
input: John Doe
output: Doe, John
So far my program takes care only of the first example and I can't figure out on how to take care of the second example.
So far here is what I got.
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
int main()
{ using namespace std;
string first_name, last_name;
char middle_name[20];
cout << "Enter your first name, middle name or initial and last name in that order\n";
cin >> first_name >> middle_name >> last_name;
cout << endl;
cout << last_name << ", " << first_name << " " << middle_name[0] << "." << endl;
return 0;
}