Answer to Question #274541 in C++ for Dylo

Question #274541

C++ program that accepts somebody's name in any case then outputs it in the proper case


1
Expert's answer
2021-12-03T02:06:00-0500


#include <iostream>
#include <string>
using namespace std;




string nameToProperCase(string name) {


	for (int x = 0; x < name.length(); x++)
	{
		if (x == 0)
		{
			name[x] = toupper(name[x]);
		}
		else if (name[x - 1] == ' ')
		{
			name[x] = tolower(name[x]);
		}else{
			name[x] = tolower(name[x]);
		}
	}


	return name;
}


int main()
{
	string name;
	cout<<"Enter name: ";
	getline(cin,name);
	


	cout<<"The proper case: "<<nameToProperCase(name)<<"\n";
	
	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment