I haven't analyzed it carefully to see exactly where your indices are getting messed up, but you should be able to see that the way you are playing with them are asking for trouble on lines 50-59.
A couple of comments to help you reconsider the way you have written it (for something simpler):
Lines 17-18, 33-25: Why are you doing this to your names? The assignment asks you to store the name, not the name + other characters.
(The problem is that you are trying to pre-process or optimize something that doesn't need it later.)
Line 33: Why are you using 44 instead of
','? If you want a comma, use a comma. [edit] This shouldn't matter if you fix things right. See below[/edit]
Line 48: You are modifying the
firstName again. Don't do that. (It should only contain the first name, as per the instructions you've been given.)
Lines 51-61: Since you are already using
strcat(), why are you not using it here?
1 2 3 4 5
|
fullName[0] = '\0'; // Important to make it a properly-terminated empty string
strcat( fullName, last );
strcat( fullName, ", " );
...
|
Lines 63-64: Why are you printing the name one letter at a time?
|
cout << fullName << endl;
|
Hope this helps.