this is a homework assignment i have read this chapter many times over it does not explain how to do exactly what i need to do. i have worked on this program for almost two weeks. this class is online and that makes it harder for me. i would appreciate any help or input someone is willing to give me. the program is suppose to ask the user for their full name with spaces between first, middle, last after the user inputs their full name. the program should display their full name followed by their 3 letter initials. i can't figure out how to search for the spaces in the name input and keep the first char and delete the rest. my book only gives examples where a name is predetermined and the length is known. in my program this information will not be known. if anyone will help i would appreciated. thanks
[tag]
[tag]Code://Purpose: //Author: //Date: //Input: //Output: #include <iostream> #include <string> using std::cout; using std::cin; using std::endl; using std::string; int main () { //declare variables string name = " "; string initials = ""; string currentChars = ""; int numChars = 0; int subscript = 0; // get name cout << "Enter your full name include spaces between first,middle,last: "; cin >> name; cout << name; //determine number of characters numChars = static_cast<int>(name.length()); while (subscript < numChars) { currentChars = name.substr(subscript, 1); if (currentChars == " ") { name.erase(subscript, 1); numChars = numChars -1; } else subscript = subscript + 1; //end if //end while } //dispaly initials cout << "Initials: " << initials << endl; return 0; } [