Hello everyone, I am having a problem with this project at the moment so far i have this. I would be very thankful if someone can help me figure out what i am doing wrong and how i can finish writing this code getting so confused. :S
The assignment is:
You are to write a program to accept a single entry (with spaces) of a person's name in the form of; Mr. John Smith
Then out put the following;
4 letters in the first name (John)
5 letters in the last name (Smith)
The program should ask if you would like to process another student (loop).
int main(int argc, constchar *argv)
constint MAX_NAME_LENGTH = 4;
constint MAX_FAMILY_LENGTH = 5;
size_t firspace = 0;
size_t secspace = 0;
// Assumes 3 entries separated by a space.
// Doesn't check if entries are incomplete or more than one space is entered.
cout << "Enter Title, First and Last Name: ";
if ((secspace-1) - (firspace+1) >= MAX_NAME_LENGTH)
first = name.substr(firspace+1, MAX_NAME_LENGTH);
first = name.substr(firspace+1, secspace-(firspace+1));
last = name.substr(secspace+1,MAX_FAMILY_LENGTH);
cout << "\n\nFirst name: " << first << "\n";
cout << "Last name: " << last << "\n\n";
cout << "Run again (Y/N)? ";
cin >> runagain;
cin.ignore(); // need this to flush the buffer for the getline().
runagain = toupper(runagain);
} while ((runagain != 'Y') && (runagain != 'N'));
} while (runagain == 'Y');