#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main ()
{
int firstMiddleLast;
string name = "Jim Anderson Smith ";
int index;
char ch;
cout << "enter a name in the format First Middle Last: ";
cin >> firstMiddleLast;
index = name. find(' ');
cout << "First Name: " << name.substr(0, index) << endl;
name = name.substr(index+1, name.length()-1);
index = name.find(' ');
cout << "Middle Name: " << name.substr(0, index) << endl;
name = name.substr(index+1, name.length()-1);
cout << "Last Name: " << name << endl;
ch = toupper(firstMiddleLast.at(0));
firstMiddleLast = ch + firstMiddleLast.substr(1, name.length());
cout << "Initial:" <<
<< firstMiddleLast << endl;
system("pause");
}
This is my code and I've been struggling with this for a long time now. Can someone tell me what I am doing wrong, I'm working with C++ and I'm suppose to get the Initials to appear but i can't seem to be able to get it. I'm still unsure as to how to use string.at, which separates the characters i believe.
This post has been edited by jimblumberg: 06 February 2012 - 05:19 PM
Reason for edit:: Added missing Code Tags, Please learn to use them.

New Topic/Question
Reply



MultiQuote





|