I need a function that takes a string and returns initials such as Bob Burnett becoming B.B. string CreateAcronym(string userPhrase);int main() {while (true){string userPhrase;getline(cin, userPhrase); if (userPhrase == "") {break; }cout << CreateAcronym(userPhrase) << endl;}return 0;}string createAcronym( const string && userPhrase ) {int i;string acronym;bool use_next = true; for (i=0; i < userPhrase.size(); i++){char character = userPhrase.at(i);int ascii = (int)character;if(ascii > 64 && ascii < 91 && use_next == true){acronym += character;use_next = false;} else if(ascii == 32){use_next=true;}else{use_next = false;}}return acronym;} Please fix my program using c++.
I need a function that takes a string and returns initials such as Bob Burnett becoming B.B.
string CreateAcronym(string userPhrase);
int main() {
while (true)
{
string userPhrase;
getline(cin, userPhrase);
if (userPhrase == "")
{
break;
}
cout << CreateAcronym(userPhrase) << endl;
}
return 0;
}
string createAcronym( const string && userPhrase )
{
int i;
string acronym;
bool use_next = true;
for (i=0; i < userPhrase.size(); i++)
{
char character = userPhrase.at(i);
int ascii = (int)character;
if(ascii > 64 && ascii < 91 && use_next == true)
{
acronym += character;
use_next = false;
}
else if(ascii == 32)
{
use_next=true;
}
else
{
use_next = false;
}
}
return acronym;
}
Please fix my
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images