can someone tell me what is wrong with my program. it is a small problem.

this program reads in a First name, middle name or initial, last name and then outputs the last name, first name then middle initial. The problem is when you don’t give a middle name or initial then the program output Is not correct. Look below for the output. The output should just be User, Mary when middle initail or name is not given.

Why are you mixing C and C++ style I/O? As a general rule that is not routinely recommended.

Use a conditional statement to print the middle name. If the middle name is empty then don't print it.

Option 1:
If the middle name is declared as an object of STL string class then empty() is a class method you can use.

Option 2:
If middle name is a C style string, then you can use middleName[0] = '\0'; as a default value to make it empty. Then check the first element of middleName to see if it is something other than the null char before printing it out.

Another way to do this is have the whole name entered on one line than parse through the string and pull the names out of it. A good way would be to see how many space are in the string. if there are 2 spaces than you know you have a middle name or initial. If there is only one space than you only have a first and last name.